I have two arrays:
$array_one = array(1=>6000,2=>500);
$array_two = array(1=>6500,2=>250);
I would like to compare the 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 perform this type of operation using a loop or something else?
You access array values using the square bracket notation [index], therefore you can simply reference 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 this;
for($i=1;$i<=count($array_one);$i++) {
if($array_one[$i] > $array_two[$i]) {
echo "ok";
}
else {
echo "not allowed";
}
}
Hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With