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
}
}
精彩评论