@orpha
To remove elements from an array in PHP, you can use several built-in functions depending on your use case:
Here's an example:
1 2 3 |
$array = array('apple', 'banana', 'orange', 'grape'); unset($array[2]); // removes 'orange' from the array print_r($array); // prints Array ( [0] => apple [1] => banana [3] => grape ) |
Here's an example:
1 2 3 |
$array = array('apple', 'banana', 'orange', 'grape'); array_splice($array, 1, 2); // removes 'banana' and 'orange' from the array print_r($array); // prints Array ( [0] => apple [1] => grape ) |
Here's an example:
1 2 3 4 5 |
$array = array('apple', 'banana', 'orange', 'grape'); $array = array_filter($array, function($value) { return $value != 'orange'; // removes 'orange' from the array }); print_r($array); // prints Array ( [0] => apple [1] => banana [3] => grape ) |