I have a Array
of which I need to filter, I am using array_filter the following way:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
var_dump(array_filter($arr, function($v, $k) {
return $k == 'b' || $v == 4;
}, ARRAY_FILTER_USE_BOTH));
?>
Effectively it works and returns the filtered result that is the index b
and index d
, but to me what I would like it to be filtered more precisely if the index b
is Value 2
.
Try as follows:
<?php
$arr = ['a' => 1, 'b' => 2, 'c' => 3, 'd' => 4];
var_dump(array_filter($arr, function($v, $k) {
return $k == 'b' && $v == 4;
}, ARRAY_FILTER_USE_BOTH));
?>
But it does not return any value to me.