View Full Version : Resolved array_search() for values over a certain number?

08-08-2012, 05:17 AM

I'm trying to search for any number greater than or equal to 1.
I know this must be really simple, but I can't seem to find how to do this?

array_search(1, $array);

I also thought of:

$limit >= 1;
array_search($limit, $array);

I'm not even sure if that's legal syntax lol...

08-08-2012, 06:53 AM
Use a filter.

define('GREATER_THAN', 0);
function greaterThanOne($v)
return is_numeric($v) ? $v >= GREATER_THAN : false;

$a = range(-10, 10);
print_r(array_filter($a, 'greaterThanOne'));

You need to use a defined constant or a global (not recommended).

08-08-2012, 06:12 PM
Thanks Fou! I will check it out!