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

前端 未结 4 745
悲哀的现实
悲哀的现实 2021-01-13 04:50

Example:

$arr = array(1 => \'Foo\', 5 => \'Bar\', 6 => \'Foobar\');
/*... do some function so $arr now equals:
    array(0 => \'Foo\', 1 => \'         


        
4条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-13 05:09

    Not that I know of, you might have already checked functions here

    but I can imagine writing a simple function myself

    resetarray($oldarray)
    {
    for(int $i=0;$i<$oldarray.count;$i++)
         $newarray.push(i,$oldarray[i])
    
    return $newarray;
    }
    

    I am little edgy on syntax but I guess u got the idea.

提交回复
热议问题