I have an array:
Array ( [0] => ololo [2] => test [3] => haha [7] => nice )
How can I change the indexes of the array to this:
Array ( [0] => ololo [1] => test [2] => haha [3] => nice )
The array_replace() function replaces the values of the first array with the values from following arrays. Tip: You can assign one array to the function, or as many as you like. If a key from array1 exists in array2, values from array1 will be replaced by the values from array2.
The re-index of an array can be done by using some inbuilt function together. These functions are: array_combine() Function: The array_combine() function is an inbuilt function in PHP which is used to combine two arrays and create a new array by using one array for keys and another array for values.
The array_flip() function flips/exchanges all keys with their associated values in an array.
From PHP.net:
array_values() returns all the values from the input array and indexes the array numerically.
Source
$arr = array_values($arr);
array_values() is probably what you want. See: http://php.net/function.array-values
$myArray = array_values($myArray);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With