开发者

Is there a function in PHP that will remove empty cells from an array?

开发者 https://www.devze.com 2023-03-24 23:58 出处:网络
After merging several arrays I run into the issue of having undeclared cells in an array. For example:

After merging several arrays I run into the issue of having undeclared cells in an array. For example:

A开发者_StackOverflowrray ( [0] => 713 [1] => 714 [4] => 712 [6] => 428 [7] => 711 [8] => 515 [9] => 645 )

I have written a function to rewrite the array without the missing indexes but I was wondering if there is already a built-in function that does this?


$array = array_values($array);

You can recreate the array using array_values and the keys will be "fresh."

Notes

  • This will remove all previous keys and replace them with the zero-based set of integers.


What are you using to merge array? If you use array_merge() ( http://www.php.net/manual/en/function.array-merge.php ), numeric keys will automatically be renumbered.

0

精彩评论

暂无评论...
验证码 换一张
取 消