开发者

Array diff with multilevel array

开发者 https://www.devze.com 2023-04-10 22:09 出处:网络
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 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

精彩评论

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