如何为多维数组应用in_array


How to apply in_array for mutidimensional array

$categories => Array([0] => Jewelry & Accessories,[1] => Pet Care)
$categories_master => Array([0] => Jewelry & Accessories,[1] => Apparel,[2] => Beauty & Fragrance)

我有两个像上面这样的数组,

我必须像这样in_array($categories,$categories_master)检查,我知道它不起作用,但我需要为与数组匹配的任何人返回 1 或 true $categories_master

执行array_intersect(返回一个数组,其中包含$categories_master中存在的所有$categories值),并转换为布尔值。如果返回数组包含项目,它将返回 true,否则返回 false。

(bool) array_intersect( $categories, $categories_master );

此外,如果返回的数组不为空,这将计算为 truefalse为空数组:

if(array_intersect( $categories, $categories_master )) {
    //there are one or more matches
}