php - Reset the numeric keys of an array -


i have array this

$array = array(   1 => 'one',   2 => 'two',   3 => 'three',   'row' => 'four',   'newrow' => 'five', ); 

i need re-index numeric keys - 1, 2, 3.

expected output:

$array = array(   0 => 'one',   1 => 'two',   2 => 'three',   'row' => 'four',   'newrow' => 'five', ); 

i've tried array_values, string keys gets indexed.

what best way this?

thanks.

use array_merge reindex array.

the code:

<?php $array = array(     1 => 'one',     2 => 'two',     3 => 'three',     'row' => 'four',     'newrow' => 'five', ); $reindexed_array = array_merge($array); var_dump($reindexed_array); 

the result:

array(5) {     [0]=> string(3) "one"     [1]=> string(3) "two"     [2]=> string(5) "three"     ["row"]=> string(4) "four"     ["newrow"]=> string(4) "five" } 

a working example can find here: https://3v4l.org/om72e. more information array_merge: http://php.net/manual/en/function.array-merge.php


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -