$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 );
此外,如果返回的数组不为空,这将计算为 true
,false
为空数组:
if(array_intersect( $categories, $categories_master )) {
//there are one or more matches
}