我有这个数组:
Array ( [702a4584] => Array ( [type] => folder [id] => 702a4584 ) [b547b3a9] => Array ( [type] => folder [id] => b547b3a9 ) [fcb0d055] => Array ( [type] => page [id] => fcb0d055 ) )
我想过滤数组,只保留类型“文件夹”:
Array ( [702a4584] => Array ( [type] => folder [id] => 702a4584 ) [b547b3a9] => Array ( [type] => folder [id] => b547b3a9 ) )
我可以做到这一点,但我需要一个通用的功能:
$temp = array(); foreach($array as $key => $value) { if($value['type'] =="folder") { $temp[$key] = $value; } }
你可以使用
原文链接:https://www.f2er.com/php/139136.htmlarray_filter
:
$filtered = array_filter($array,function($v) { return $v['type'] == 'folder'; });