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? Quote 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 ? Quote 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 ? Quote 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; } ?> Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.