I know that it would be trivial to code yourself, but it’s in the interest of not having more support code if it is already built into PHP, is there a built-in function to “compress” the PHP array? In other words, let's say I create an array this way:
$array = array();
$array[2000] = 5;
$array[3000] = 7;
$array[3500] = 9;
What I want is an array, where $ array [0] == 5, $ array [1] == 7, $ array [2] == 9.
I could do this:
function array_defragment($array) {
$squashed_array = array();
foreach ($array as $item) {
$squashed_array[] = $item;
}
return $squashed_array;
}
... but it looks like it will be built into PHP - I just can't find it in the docs.
source
share