How to perform a true false comparison of two different array values
I have two arrays:
$array_one = array(1=>6000,2=>500);
$array_two = array(1=>6500,2=>250);
I would like to compare values ββwith >
or <
like this:
if(6000 > 6500){
echo "ok";
}else{ echo "not allowed";}
if(500> 250){
echo "ok";
}else{ echo "not allowed";}
How can I accomplish this type of operation with a loop or something?
+3
source to share
3 answers
You access the values ββof the array using the square bracket notation [index]
, so you can simply refer to the values ββusing their index;
if($array_one[1] > $array_two[1]) {
echo "ok";
}
else {
echo "not allowed";
}
and then you can put that in a loop like:
for($i=1;$i<=count($array_one);$i++) {
if($array_one[$i] > $array_two[$i]) {
echo "ok";
}
else {
echo "not allowed";
}
}
Hope it helps.
+4
source to share