Hello Readers!, If you have an array whose key index are missing then you could use the 'array_values' function to easily reindex the array.
Let's see the example below:-
<?php
$array = array( 0 => 'string1', 2 => 'string2', 4 => 'string3', 5 => 'string4');
$arrays =$array;
print_r($array);
echo "<br> now the reindex array <br>";
$myArray = array_values($arrays);
print_r($myArray);
?>
Output:-
Array
(
[0] => string1
[2] => string2
[4] => string3
[5] => string4
)
now the reindex array
Array
(
[0] => string1
[1] => string2
[2] => string3
[3] => string4
)
0 Comment(s)