开发者

how to find next index in php array?

开发者 https://www.devze.com 2023-03-17 17:51 出处:网络
I have multidimensional array with mixed index ie int and string values. ex. [\'abc\'][p][8][5][\'amol\'][\'jon\']

I have multidimensional array with mixed index ie int and string values.

ex.

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

at Ce开发者_如何学运维rtain point i know the need to check index after index 'abc' , whether it is int or string how can i do that?


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


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; 
}

then use is_int() to check int or string.

0

精彩评论

暂无评论...
验证码 换一张
取 消