How to remove elements from a PHP array?

In PHP, you can use the unset() function to remove elements from an array. The unset() function takes one or more keys of array elements as parameters and removes them from the array.

Here is an example of removing elements from an array:

$fruits = array("apple", "banana", "orange");
unset($fruits[1]); // 删除索引为1的元素(banana)

print_r($fruits); // 输出:Array ( [0] => apple [2] => orange )

In the example above, the unset() function was used to remove the element at index 1 (“banana”) from the array $fruits. Finally, the print_r() function was used to display the array after the deletion of the element.

bannerAds