如何获取特定索引下方的数组的所有索引


How to get all the indexes of an array that are below a specific index?

例如,这是一个数组:

$array = array(
    'firstIndex' => 'Tom',
    'secondIndex' => 'John',
    'thirdIndex' => 'Cavanagh',
    'fourthIndex' => 'Gustin',
    'fifthIndex' => 'Stephen',
    'sixthIndex' => 'Amell',
    'seventhIndex' => 'Robbie',
    'eighthIndex' => 'Cisco'
);

有什么方法可以获取"第四索引"键之后的所有索引吗?喜欢这个:

$someVar = array_get_indexes_after_key('fourthIndex', $array);
var_dump($someVar);

将返回:

array(4) {
["fifthIndex"]=>
string(7) "Stephen"
["sixthIndex"]=>
string(5) "Amell"
["seventhIndex"]=>
string(6) "Robbie"
["eighthIndex"]=>
string(5) "Cisco"
}

我该怎么做?任何建议都非常感谢。

假设您的命名索引始终相同,则可以使用 array_slice() 和偏移量。