Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built-in PHP function to reset the indexes of an array?

Tags:

arrays

php

Example:

$arr = array(1 => 'Foo', 5 => 'Bar', 6 => 'Foobar');
/*... do some function so $arr now equals:
    array(0 => 'Foo', 1 => 'Bar', 2 => 'Foobar');
*/
like image 702
James Skidmore Avatar asked Jul 28 '09 19:07

James Skidmore


2 Answers

Use array_values($arr). That will return a regular array of all the values (indexed numerically).

PHP docs for array_values

like image 64
Brian Ramsay Avatar answered Oct 14 '22 10:10

Brian Ramsay


array_values($arr);
like image 26
skrebbel Avatar answered Oct 14 '22 12:10

skrebbel