i have array in php this
$numbers = array('1','3','4','5','6','7','8','9','0','11','123','89');
and current number can random
$currentnumber = 32;
what need output first number array lower $currentnumber
, first higher number array bigger $currentnumber
i know can output lower , bigger, put need 1 :(
foreach ($numbers $number){ if ($number > $currentnumber){ echo $number .' number bigger'; } else{ echo $number .' number lower'; } }
below code find first number array lower $currentnumber , first higher number array bigger $currentnumber
$firstlowestnum=$firsthighernum=null; $currentnumber=32; $numbers = array('1','3','4','5','6','7','8','9','0','11','123','89'); foreach ($numbers $number){ if ($number > $currentnumber && is_null($firsthighernum)){ $firsthighernum =$number; } else if(is_null($firstlowestnum)){ $firstlowestnum =$number; } } var_dump($firstlowestnum,$firsthighernum);
Comments
Post a Comment