PHP | 通过重新排序从数组中删除元素?

Ken*_*man 9 php arrays pointers return unset

如何删除数组的元素,然后重新排序,而不在数组中有空元素?

<?php
   $c = array( 0=>12,1=>32 );
   unset($c[0]); // will distort the array.
?>
Run Code Online (Sandbox Code Playgroud)

答案/解决方案:array array_values(array $ input).

<?php
   $c = array( 0=>12,1=>32 );
   unset($c[0]);
   print_r(array_values($c));
   // will print: the array cleared
?>
Run Code Online (Sandbox Code Playgroud)

Wim*_*Wim 14

array_values($c)
Run Code Online (Sandbox Code Playgroud)

将返回一个只包含值的新数组,线性索引.