How can you remove an element from an array in PHP?
You can use the unset() function to remove a specific element from an array. The unset() function accepts one or more parameters, which can be a variable or a reference to an array element. If the parameter is a reference to an array element, the unset() function will delete that element.
Here is an example demonstrating how to remove an element from an array.
<?php
$array = array('apple', 'banana', 'orange');
unset($array[1]); // 删除数组中索引为1的元素(banana)
print_r($array); // 输出Array([0] => apple [2] => orange)
?>
In the example above, the unset() function was used to remove the element at index 1 in the array, which is the element ‘banana’. Finally, by using the print_r() function to display the array, it can be seen that the element has been successfully deleted.