Created
August 29, 2013 17:45
-
-
Save PabloVallejo/6381161 to your computer and use it in GitHub Desktop.
get_first_greather_int_index
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 | |
/** | |
* Return the key of the first elements | |
* greater than the one passed. | |
* | |
* <code> | |
* | |
* // Get the index of the first number greater than 15. | |
* // returns "1" | |
* echo get_first_greather_int_index( array( 9, 19, 29, 49 ), 15 ); | |
* | |
* </code> | |
* | |
* @param { arr } array to iterate | |
* @param { int } value to compare to | |
* @return { int || bool } first fit element index or false. | |
*/ | |
function get_first_greather_int_index( $arr, $item ) { | |
foreach( $arr as $k => $v ) | |
if ( $v >= $item ) | |
return $k; | |
return false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment