PabloVallejo
8/29/2013 - 5:45 PM

get_first_greather_int_index

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;
	}