原二维数组如下
$skunmae=array:3 [
0 => array:2 [
"products_id" => 7
"sku" => "星耀咖-星耀系列"
]
1 => array:2 [
"products_id" => 7
"sku" => "星耀橙-星耀系列"
]
2 => array:2 [
"products_id" =>8
"sku" => "红色"
]
]
实现代码如下:目标是搜索products_id=7的数据
$a=$v['products_id'];
$son=array_filter($skuname, function($t) use ($a) {
return $t['products_id'] == $a;
});
打印$son结果如下
array:2 [
0 => array:2 [
"products_id" => 7
"sku" => "星耀咖-星耀系列"
]
1 => array:2 [
"products_id" => 7
"sku" => "星耀橙-星耀系列"
]
]