php - Loop and comparing each element of array? -


i trying compare each element 2 array $min , $max

$test = false; $min = array(2,3,3,55,556); $max = array(22,32,4,56,557); foreach($min $key=>$val){     foreach($max $k=>$v){       if($val >= $v){         $test=true;         break;       }   } }   if($test){   echo "a not greater or equal b"; }else{   echo "you can save now"; } 

what wrong?because got message here

  not greater or equal b 

thanks

you're comparing every value $min every value $max (until hit value of $min greater value in $max), , 55 $min greater 22 $max, $test set true.

are trying compare corresponding $min , $max values?

$test = false; $min = array(2,3,3,55,556); $max = array(22,32,4,56,557); foreach($min $key=>$val){    if($val >= $max[$key]){      $test=true;      break;    } } 

Comments

Popular posts from this blog

apache - Add omitted ? to URLs -

redirect - bbPress Forum - rewrite to wwww.mysite prohibits login -

php - How can I stop spam on my custom forum/blog? -