The implementation code for removing elements from the php array
- 2020-05-19 04:18:35
- OfStack
<?php
$arr = array('a','b','c','d');
unset($arr[1]);
print_r($arr);
?>
After print_r($arr), the result is not that, but Array ([0] = > a [2] = > c [3] = > d
So how do you get the missing elements to be filled in and the array to be re-indexed? The answer is array_splice () :
<?php
$arr = array('a','b','c','d');
array_splice($arr,1,1);
print_r($arr); // <span style="font-family: Simsun;font-size:16px; ">Array ( [0] => a [1] => c [2] => d )</span>
?>