...

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



RonnyNishimoto
08-08-2012, 04:17 AM
Hi!

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?



<?php
array_search(1, $array);
?>


I also thought of:



<?php
$limit >= 1;
array_search($limit, $array);
?>


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

Fou-Lu
08-08-2012, 05: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).

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum