This article mainly introduces how PHP uses unset() to delete a certain unit (key) in an array ) method, the example analyzes the usage skills of unset function when deleting array units. Friends in need can refer to it
The example in this article describes how PHP uses unset() to delete a certain unit (key) in an array. Share it with everyone for your reference. The specific analysis is as follows:
unset can delete either a variable or a unit in an array. But be aware that the array will not be reindexed.
Examples are as follows:
?
3 4
5
6
|
$arr = array("Chaoyang District", "Haidian District", "Xicheng District", "Dongcheng District", "Fengtai District"); unset($arr[3]); echo ""; |
1 |
Array ( [0] => Chaoyang District [1] => Haidian District [2] => Xicheng District [4] => Fengtai District ) |