我正在寻找来自php数组的项,其中类型是"key“。显示其中一个类型为-2类型的所有项目。
谢谢
<?php $gallery = [];
$gallery [1] = [
"Name" => "Three Full Length Mirrors",
"Description" => "Three mirrors with silver aluminum profile. ",
"image" => "full-mirror.jpg",
"type" => [
"type-1",
"type-2",
"type-3"
]
];
?>发布于 2019-02-12 01:16:46
您可以使用array_filter对数组进行预筛选,但是将测试放在foreach循环中也同样容易:
foreach ($gallery as $g) {
if (!in_array('type-2', $g['type'])) continue;
// rest of code
}发布于 2019-02-12 01:19:52
<?php
$result = array_filter($gallaries, function($gallery){
// If below is true element stays, the false cases get removed from array
return in_array('type-2',$gallery['type'])
});https://stackoverflow.com/questions/54641462
复制相似问题