-3

I have this this multilevel array :

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

Now, I have another array that is simple : $codescart[] . Example $codescart[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 ...

2
  • 2
    Please post example data as an initialization script if you want us to test. Just knowing that $productpacks[0][0] is 4355 is not enough... tx Commented Oct 3, 2011 at 14:04
  • This should work. Please post a complete example as Mathieu said. Commented Oct 3, 2011 at 14:06

1 Answer 1

1

Why not just use in_array()?

foreach($productpacks as $pack) {
  if (in_array($pack, $codescart)) {
    // $cart contains this pack
  }
}   
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.