$array
, у которых 'property'
равен 2?$array = [
[
'id' => 1,
'property' => 2,
],
[
'id' => 2,
'property' => 2,
],
[
'id' => 3,
'property' => 1,
],
[
'id' => 4,
'property' => 1,
],
];
$array = [
[
'id' => 2,
'property' => 2,
],
[
'id' => 1,
'property' => 2,
],
[
'id' => 3,
'property' => 1,
],
[
'id' => 4,
'property' => 1,
],
];
$key = 'property';
$val = 2;
$toReverse = array_filter($array, function($n) use($key, $val) {
return $n[$key] === $val;
});
$newArray = array_map(function($n) use(&$toReverse, $key, $val) {
return $n[$key] === $val ? array_pop($toReverse) : $n;
}, $array);