Monday, August 3, 2015

Reset PHP Array Index


I have a PHP array that looks like this:
[3] => Hello
[7] => Moo
[45] => America
What PHP function makes this?
[0] => Hello
[1] => Moo
[2] => America
shareimprove this question
up vote88down voteaccepted
The array_values() function [docs] does that:
$a = array(
    3 => "Hello",
    7 => "Moo",
    45 => "America"
);
$b = array_values($a);
print_r($b);
Array
(
    [0] => Hello
    [1] => Moo
    [2] => America
)
shareimprove this answer
   
Thank you! Worked like a charm. –  Walter Johnson Sep 24 '11 at 14:27
3 
Makes too much sense, oi it's early. –  phatskat Feb 18 '13 at 13:14