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
Post a Comment