Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Perform True False Comparison on 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 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?

like image 400
Rammehar Sharma Avatar asked Apr 10 '26 23:04

Rammehar Sharma


1 Answers

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.

like image 99
worldofjr Avatar answered Apr 13 '26 13:04

worldofjr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!