array_filter
false
Исходный Массив
$array["PHPDevelopers"] = [
["Name" => 'Dan Englishby', 'Age' => '99', 'DeveloperLevel' => '3', 'Email' => 'dan@englishby.com', 'Gender' => 'Male'],
["Name" => 'Del Smith', 'Age' => '33', 'DeveloperLevel' => '8', 'Email' => 'del@smith.com', 'Gender' => 'Male'],
["Name" => 'Jame Raphael', 'Age' => '27', 'DeveloperLevel' => '4', 'Email' => 'jame@raphael.com', 'Gender' => 'Male'],
["Name" => 'Jayna Honaker', 'Age' => '42', 'DeveloperLevel' => '9', 'Email' => 'jame@raphael.com', 'Gender' => 'Female'],
["Name" => 'Stephine Ransome', 'Age' => '42', 'DeveloperLevel' => '4', 'Email' => 'stephine@ransome.com', 'Gender' => 'Female'],
];
$array["C#Developers"] = [
["Name" => 'Craig Woolard', 'Age' => '22', 'DeveloperLevel' => '4', 'Email' => 'craig@woolard.com', 'Gender' => 'Male'],
["Name" => 'Tiffiny Minich', 'Age' => '21', 'DeveloperLevel' => '3', 'Email' => 'tiffiny@minich.com', 'Gender' => 'Female'],
["Name" => 'Chad Lanser', 'Age' => '55', 'DeveloperLevel' => '7', 'Email' => 'chad@lanser.com', 'Gender' => 'Male'],
["Name" => 'Latisha Langlais', 'Age' => '25', 'DeveloperLevel' => '2', 'Email' => 'latisha@langlais.com', 'Gender' => 'Female'],
["Name" => 'Dave Gaona', 'Age' => '63', 'DeveloperLevel' => '9', 'Email' => 'dave@gaona.com', 'Gender' => 'Male'],
];
var_dump
Фильтрация Многомерного Массива по Ключу
PHPDevelopers
array_filter
ARRAY_FILTER_USE_KEY
$phpDevs = array_filter($array, function ($key) {
return $key == 'PHPDevelopers';
}, ARRAY_FILTER_USE_KEY);
Результат:
array (
'PHPDevelopers' =>
array (
0 =>
array (
'Name' => 'Dan Englishby',
'Age' => '99',
'DeveloperLevel' => '3',
'Email' => 'dan@englishby.com',
'Gender' => 'Male',
),
1 =>
array (
'Name' => 'Del Smith',
'Age' => '33',
'DeveloperLevel' => '8',
'Email' => 'del@smith.com',
'Gender' => 'Male',
),
2 =>
array (
'Name' => 'Jame Raphael',
'Age' => '27',
'DeveloperLevel' => '4',
'Email' => 'jame@raphael.com',
'Gender' => 'Male',
),
3 =>
array (
'Name' => 'Jayna Honaker',
'Age' => '42',
'DeveloperLevel' => '9',
'Email' => 'jame@raphael.com',
'Gender' => 'Female',
),
4 =>
array (
'Name' => 'Stephine Ransome',
'Age' => '42',
'DeveloperLevel' => '4',
'Email' => 'stephine@ransome.com',
'Gender' => 'Female',
),
),
);
array_filter
$phpDevs = array_filter($array, function ($key) {
return $key == 'PHPDevelopers';
});
Результат:
array (
);
Фильтрация Многомерного Массива по Значению
$age = 40;
$phpDevsOver40 = array_filter($array["PHPDevelopers"], function ($value) use ($age) {
return ($value["Age"] > $age);
});
Результат:
array (
0 =>
array (
'Name' => 'Dan Englishby',
'Age' => '99',
'DeveloperLevel' => '3',
'Email' => 'dan@englishby.com',
'Gender' => 'Male',
),
3 =>
array (
'Name' => 'Jayna Honaker',
'Age' => '42',
'DeveloperLevel' => '9',
'Email' => 'jame@raphael.com',
'Gender' => 'Female',
),
4 =>
array (
'Name' => 'Stephine Ransome',
'Age' => '42',
'DeveloperLevel' => '4',
'Email' => 'stephine@ransome.com',
'Gender' => 'Female',
),
);
Заключение
array_filter
array_filter