如何在php数组中找到下一个索引?

时间:2011-07-07 09:37:40

标签: php arrays

我有一个带有混合索引的多维数组,即int和string值。

离。

['abc'][p][8][5]['amol']['jon']

在某些时候我知道需要在索引'abc'之后检查索引,无论是int还是string我该怎么做?

2 个答案:

答案 0 :(得分:0)

next($array);             //> Advancing
is_numeric(key($array));  //> Checking

答案 1 :(得分:-1)

http://fi2.php.net/manual/en/function.key.php

function array_key_relative($array, $current_key, $offset = 1) 
{ // create key map $keys = array_keys($array); 
// find current key $current_key_index = array_search($current_key, $keys); 
// return desired offset, if in array, or false if not 
if(isset($keys[$current_key_index + $offset])) 
{ return $keys[$current_key_index + $offset]; } return false; 
}

然后使用is_int()来检查int或string。