I have this array:
Array
(
[702a4584] => Array
(
开发者_Go百科 [type] => folder
[id] => 702a4584
)
[b547b3a9] => Array
(
[type] => folder
[id] => b547b3a9
)
[fcb0d055] => Array
(
[type] => page
[id] => fcb0d055
)
)
I want to filter the array such that only type "folder" will remain:
Array
(
[702a4584] => Array
(
[type] => folder
[id] => 702a4584
)
[b547b3a9] => Array
(
[type] => folder
[id] => b547b3a9
)
)
I could do this, but I'll be needing a generic function:
$temp = array();
foreach($array as $key => $value)
{
if($value['type'] =="folder")
{
$temp[$key] = $value;
}
}
You could use array_filter
:
$filtered = array_filter($array, function($v) { return $v['type'] == 'folder'; });
$input = Array(1,2,3,1,2,3,4,5,6);
$input = array_map("unserialize", array_unique(array_map("serialize", $input)));
精彩评论