amolv Posted July 7, 2011 Share Posted July 7, 2011 Hi, I have array with mixed indexes, i wanted find after 'xyz' index, what is next index int value or string, how can i do that? Link to comment https://forums.phpfreaks.com/topic/241307-in-php-array-find-next-index/ Share on other sites More sharing options...
TeNDoLLA Posted July 7, 2011 Share Posted July 7, 2011 This helps: http://fi2.php.net/manual/en/function.next.php ? Link to comment https://forums.phpfreaks.com/topic/241307-in-php-array-find-next-index/#findComment-1239490 Share on other sites More sharing options...
amolv Posted July 7, 2011 Author Share Posted July 7, 2011 @TeNDoLLA i need index value , something where i can pass my search index and get next index ? Link to comment https://forums.phpfreaks.com/topic/241307-in-php-array-find-next-index/#findComment-1239493 Share on other sites More sharing options...
TeNDoLLA Posted July 7, 2011 Share Posted July 7, 2011 I found this from php manual under the key() functions comments. This should do it. <?php // array_key_relative - Returns a key in an associative array relative to another key without using foreach. Very useful for finding previous key or finding next key in array, etc // - Written by Jamon Holmgren (www.jamonholmgren.com). Last revised 8/18/2009. Free for any use. // function array_key_relative(array $array, string $current_key, int $offset) 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; } ?> Link to comment https://forums.phpfreaks.com/topic/241307-in-php-array-find-next-index/#findComment-1239494 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.