Just capturing and unsetting the value is much better (and most likely faster) , but in any case, you can just count
$result = array();
$idx = 0;
foreach ($input as $key => $value)
{
if ($key == 'more')
{
$result[] = key(array_splice($input, $idx, 1));
}
$idx++;
}
print_R($result);
print_R($input);
gives
Array
(
[0] => more
)
Array
(
[who] => me
[what] => car
[when] => today
)
BUT Technically speaking, an associative key does not have a numeric index. If the input array was
$input = array
(
'who' => 'me',
'what' => 'car',
'more' => 'car',
'when' => 'today',
'foo', 'bar', 'baz'
);
2 "baz". array_slice , , , ( , ), .
, . $key === 'more', "" typecasted. , , "", . :
if(array_key_exists('more', $input)) unset($input['more']);