Reset PHP Array Index
I have a PHP array that looks like this:
[3] => Hello
[7] => Moo
[45] => America
What PHP function makes this?
[0] => Hello
[1] => Moo
[2] => America
Solution 1:
The array_values()
function [docs] does that:
$a = array(
3 => "Hello",
7 => "Moo",
45 => "America"
);
$b = array_values($a);
print_r($b);
Array
(
[0] => Hello
[1] => Moo
[2] => America
)
Solution 2:
If you want to reset the key count of the array for some reason;
$array1 = [
[3] => 'Hello',
[7] => 'Moo',
[45] => 'America'
];
$array1 = array_merge($array1);
print_r($array1);
Output:
Array(
[0] => 'Hello',
[1] => 'Moo',
[2] => 'America'
)