1

I can't seem to find a way to this in PHP using arrays.

$id_qty1 = array(1 => 20, 2 => 30, 3 => 40); 

$id_qty2 = array(1 => 30, 2 => 20, 3 => 50); 

I would like to check one array against the other and:

if same key and bigger value do one thing

if same key and smaller value do another thing

4

1 回答 1

2

这样的事情会做到这一点:

foreach ($id_qty1 as $key => $value) {
    if (isset($id_qty2[$key])) {
        if ($id_qty2[$key] > $value) {
            // do one thing
        } else {
            // do another thing 
        }
    }
}
于 2013-08-21T20:30:52.783 回答