Skip to content

Instantly share code, notes, and snippets.

@PabloVallejo
Created August 29, 2013 17:45
Show Gist options
  • Save PabloVallejo/6381161 to your computer and use it in GitHub Desktop.
Save PabloVallejo/6381161 to your computer and use it in GitHub Desktop.
get_first_greather_int_index
<?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