开发者

Array diff with multilevel array

I have this this multilevel array :

$productpacks . Example $productpacks[0][0] is 4355 .

Now, I have another array that is simple : $codescart[] . Example $code开发者_开发知识库scart[0] is 4355 .

I am trying to differ those two like this (it does not seem to work) :

foreach($productpacks as $pack) {
    $diff = array_diff($pack, $codescart);
    if (empty($diff)) {
        // $cart contains this pack
    }
}   

Does that work for anybody ? or were is the problem if any ...


Why not just use in_array()?

foreach($productpacks as $pack) {
  if (in_array($pack, $codescart)) {
    // $cart contains this pack
  }
}   
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜