rmbarnes82 Posted July 10, 2008 Share Posted July 10, 2008 Hi, Does anyone know of a php function to re-key an array with sequential integers starting at 0? For example, lets say the function to do this is called array_rekey(): <?php $myArray = array(3=>'a', 8=>'b', 102=>'c'); array_rekey($myArray); print_r($myArray); ?> I am of course assuming here that the function takes the array by reference, and so the ouput would be: Array ( [0] => 'a' [1] => 'b' [2] => 'c' ) array_fill_keys() won't work for this. If there isn't a function that already exists to do this, please ignore. Thanks, Robin Link to comment https://forums.phpfreaks.com/topic/114112-solved-re-key-an-array-with-sequential-integers-starting-at-0/ Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 $new_array = array_values($myArray); Link to comment https://forums.phpfreaks.com/topic/114112-solved-re-key-an-array-with-sequential-integers-starting-at-0/#findComment-586493 Share on other sites More sharing options...
rmbarnes82 Posted July 10, 2008 Author Share Posted July 10, 2008 ty Link to comment https://forums.phpfreaks.com/topic/114112-solved-re-key-an-array-with-sequential-integers-starting-at-0/#findComment-586505 Share on other sites More sharing options...
DarkWater Posted July 10, 2008 Share Posted July 10, 2008 Any time. =) Link to comment https://forums.phpfreaks.com/topic/114112-solved-re-key-an-array-with-sequential-integers-starting-at-0/#findComment-586509 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.