我有一个关联的数组,
$array2 = array(
array('customer_id' => '01', 'categories' => '',),
array('customer_id' => '02', 'categories' => '',),
array('customer_id' => '03', 'categories' => '20,26,18',),
array('customer_id' => '04', 'categories' => '45,118',),
);
我需要获取类别值为 18 的数组。我已经分解了类别值并将它们签入array_filter
.
function testCategories($var)
{
$like = 18;
$categoryArray = array_column($var, 'categories');
foreach($categoryArray as $ca){
$caEplode = explode(',', $ca);
foreach($caEplode as $cae){
return($cae == $like);
}
}
}
print_r(array_filter($array2,"testCategories"));
但我返回一个空字符串。谁能帮帮我吗?