PHP foreach比较2个多维数组

时间:2016-07-15 15:32:25

标签: php arrays multidimensional-array

我在下面有这个函数在没有& $rQtyOld==$data1[$k1]['rQty']部分的情况下工作正常,但是当我将它作为附加条件添加时,它返回false并且不执行代码$data1[$k1]['rQty']=$addition[$i]['rQty'];

我在某些情况下验证了$rQtyOld===$data1[1]['rQty']$rQtyOld之前以这种方式定义:$rQtyOld=$_POST['editionFormerQty'];

$ data1数组看起来像这样:

[{"name":"56.030","type":"F","rQty":"888"},{"name":"20.242","type":"T","rQty":"22"},{"name":"20.242","type":"T","rQty":"10"}]

代码

function adjustKeyToArray($data1,$addition,$rQty,$rQtyOld){
    $iLength=sizeof($addition);     
    foreach($data1 as $k1=>$v1){            
        for($i=0;$i<$iLength;$i++){             
            if($addition[$i]['name']==$data1[$k1]['name'] & 
               $addition[$i]['type']==$data1[$k1]['type'] & 
               $rQtyOld==$data1[$k1]['rQty'])
            {
                $data1[$k1]['rQty']=$addition[$i]['rQty'];                  
                return $data1;          
            }
        }       
    }
    return $data1;
}

有人可以向我解释为什么它不起作用吗? 谢谢,

0 个答案:

没有答案