如何获取低于特定索引的数组的所有索引?

时间:2015-03-08 13:25:45

标签: php arrays

例如,这是一个数组:

$array = array(

    'firstIndex' => 'Tom',

    'secondIndex' => 'John',

    'thirdIndex' => 'Cavanagh',

    'fourthIndex' => 'Gustin',

    'fifthIndex' => 'Stephen',

    'sixthIndex' => 'Amell',

    'seventhIndex' => 'Robbie',

    'eighthIndex' => 'Cisco'

);

有没有什么方法可以在'fourthIndex'键后得到所有索引?像这样:

$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"
}

我该怎么做?任何建议都是真的很感激。

1 个答案:

答案 0 :(得分:0)

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

相关问题