In PHP, is there a function for finding the lowest numerical key without a value in an array? I have an array like this:
array (
0 => 'nested array',
1 => 'nested array',
2 => 'nested array',
3 => 'nested array',
6 => 'nested array',
7 => 'nested array',
)
and I would like to add a value to this array (at 4), not necessarily unique, and get its position back without altering the rest of the keys. Is the easiest way to loop through the array and test isset(), or is there an easier way?
range, then find the lowest missing one.$expected_keys = range(0, count($your_array) - 1); $missing_keys = array_diff($expected_keys, array_keys($your_array)); return min($missing_keys);