paulman888888 Posted January 7, 2010 Share Posted January 7, 2010 Hi, I've been stuck for awhile now; Want to see what the lowest group a variable can fit under. $my_var=8;// example my array (Using print_r) Array ( [0] => 7 [1] => 9 [2] => 11 ) First part of the array is just an id the second one is the one am after. I want to loop though and find the lowest number by variable can fit under so in this case my_var is 8 so the lowest number it can go under is 9. And i would like to be able to store the answer in a variable. Thankyou for your time Paul P.S Sorry if this is a newbie question. I've got back from a holiday (Spain) and i've seem to forgot alot of things Quote Link to comment Share on other sites More sharing options...
taquitosensei Posted January 7, 2010 Share Posted January 7, 2010 try this $my_var=8; $array=array(7,9,11,6); // make sure it's in numerical order sort($array); foreach($array as $test_var) { echo $my_var." | ".$test_var."\r\n"; if($my_var < $test_var) { $result=$test_var; break; } } echo $result; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.