How to re-index all subarray elements of a multidimensional array? How to re-index all subarray elements of a multidimensional array? php php

How to re-index all subarray elements of a multidimensional array?


To reset the keys of all arrays in an array:

$arr = array_map('array_values', $arr);

In case you just want to reset first-level array keys, use array_values() without array_map.


$array[9] = 'Apple';$array[12] = 'Orange';$array[5] = 'Peach';$array = array_values($array);

through this function you can reset your array

$array[0] = 'Apple';$array[1] = 'Orange';$array[2] = 'Peach';


Use array_values to reset keys

foreach($input as &$val) {   $val = array_values($val);}

http://php.net/array_values