1, the preceding has said the array as the stack and the queue when the deletion element operations, that is, in order to delete the rules. So, what if you need to remove an element from the middle of an array? We need the unset () function We're going to talk about today.
2. The unset () function allows an element in an array to be canceled, but the array does not rebuild the index, which keeps the original index, because the index in PHP has a special meaning.
3, sample display:
<?php
$arr = Array (1=> ' one ',2=> ' two ',3=> ' three ');
Delete the element unset with subscript 2
($arr [2]); will get Array (1=> ' one ',3=> ' three ')
//Use Array_values () to re-establish the index
$aar = array_values ($arr); $aar = Array (0=> ' one ',1=> ' three ')
?>4, the last code in the above example is to re-establish the array index, here I explain the following: Because after using the unset () function to delete an element, there is no way to re-establish the index subscript order. If you need a sequential index subscript, you can use the Array_values () function to recreate the index subscript order.
Note: The re-indexing of the premises says: Re-establish a subscript in the order of 0, even if your index is not named numerically, it will be indexed again.