$arr = [‘0‘=>[‘aa‘],‘1‘=>[‘c‘],‘2‘=>[‘bb‘,‘cc‘]]; unset($arr[‘1‘]); echo ‘<pre>‘; print_r($arr); echo PHP_EOL; print_r(array_values($arr));
Array ( [0] => Array ( [0] => aa ) [2] => Array ( [0] => bb [1] => cc ) ) Array ( [0] => Array ( [0] => aa ) [1] => Array ( [0] => bb [1] => cc ) )
unset索引数组指定元素后,并不会把后面元素移动到前面
需要借助array_values()函数移动下
原文地址:https://www.cnblogs.com/zxqblogrecord/p/10128110.html
时间: 2024-10-05 04:43:33