If you want to delete an element in an array, you can use the unset directly, but the index of the array does not rearrange:
<?php
$arr = Array (' A ', ' B ', ' C ', ' d ');
Unset ($arr [1]);
Print_r ($arr);
The result:
Array ([0] => a [2] => C [3] => D)
So how do you get the missing elements to be filled and the array will be indexed again? The answer is Array_splice ():
<?php
$arr = Array (' A ', ' B ', ' C ', ' d ');
Array_splice ($arr, 1,1);
Print_r ($arr);
The result:
Array ([0] => a [1] => C [2] => D)
Articles that you may be interested in
- PHP removes null-valued elements from the array (array_filter)
- PHP finds whether a value exists in the array (In_array (), Array_search (), array_key_exists ())
- How PHP deletes the first and last elements of an array
- JavaScript Array Action function summary (PUSH,POP,JOIN,SHIFT,UNSHIFT,SLICE,SPLICE,CONCAT)
- The difference between the PHP merge array + and the Array_merge
- PHP clears the empty value element in the array
- PHP presses the element to the array header (Array_unshift usage)
- PHP Array function array_walk () notes