Home >Backend Development >PHP Tutorial >How to rebuild index after deleting elements from php array?
print_r($arr), the result is not like that. The final result is Array ( [0] => a [2] => c [3] => d ) How can missing elements be filled and the array re-indexed? Use array_splice():
2, delete the specified element of the array array_search() is more practical The array_search() function, like in_array(), searches for a key value in an array. If the value is found, the key of the matching element is returned. If not found, return false
output array('1', '2', '4', '5'); If you want to re-index the array, you need to use foreach to traverse the deleted array and then re-create an array. |