0

我有两个数组:

$arr_order:

   Array
    (
        [0] => Array
            (
                [qty] => 5
                [id] => 2
                [sku] => Model 2
            )

        [1] => Array
            (
                [qty] => 2
                [id] => 3
                [sku] => Model 1
            )
    )

$arr_stock:

Array
(
    [0] => Array
        (
            [id] => 2
            [qty] => 2
        )

    [1] => Array
        (
            [id] => 3
            [qty] => 2
        )

)

如何使用foreach循环比较这两个数组?

示例:如果$arr_order[0][qty] =5 > $arr_stock[0][qty] = 2 ...

返回第三个数组:

$arr_stock_available:

Array
    (
        [0] => Array
            (
                [id] => 2
                [qty] => 2
            )
    )
4

1 回答 1

1
$i = 0;
$arr_stock_available = array();
foreach($arr_order as $data){
   if($data['qty'] > $arr_stock[$i]['qty']){
       $arr_stock_available[] = $arr_stock[$i];
    } else {
       $arr_stock_available[] = $data;
    }
    $i++;
}

使用上面的代码。

于 2013-06-26T06:16:48.170 回答