After array_filter(), how can I reset the keys to go in numerical order starting at 0 After array_filter(), how can I reset the keys to go in numerical order starting at 0 arrays arrays

After array_filter(), how can I reset the keys to go in numerical order starting at 0


If you call array_values on your array, it will be reindexed from zero.


If you are using Array filter do it as follows

$NewArray = array_values(array_filter($OldArray));


Use array_values():

<?php$array = array('foo', 'bar', 'baz');$array = array_filter($array, function ($var) {    return $var !== 'bar';});print_r($array); // indexes 0 and 2print_r(array_values($array)); // indexes 0 and 1