Created
October 26, 2020 13:52
-
-
Save mahdiyazdani/a57686e0f39cb98e24d1b4841a03342c to your computer and use it in GitHub Desktop.
Retrieve the next key in an array from given key
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Retrieve the next key in an array from given key. | |
* | |
* @since 1.0.0 | |
* @param array $arr List of items in a form of array. | |
* @param integer $key Key to search and find within the array. | |
* @return integer | |
*/ | |
function prefix_get_next_key_array( $arr, $key ) { | |
$keys = array_keys( $arr ); | |
$position = array_search( $key, $keys, true ); | |
if ( isset( $keys[ $position + 1 ] ) ) { | |
$next_key = $keys[ $position + 1 ]; | |
} | |
return $next_key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment