<?php
$data = [
['food' => 'banana', 'count' => 43],
['food' => 'bananas', 'count' => 3],
['food' => 'cheese strings', 'count' => 5],
['food' => 'tea towle', 'count' => 2],
];
$minRow = null;
$maxRow = null;
$minValue = null;
$maxValue = null;
array_map(
static function ($row) use (&$minValue, &$maxValue, &$minRow, &$maxRow) {
if (null === $minValue || $row['count'] < $minValue) {
$minValue = $row['count'];
$minRow = $row;
}
if (null === $maxValue || $row['count'] > $maxValue) {
$maxValue = $row['count'];
$maxRow = $row;
}
},
$data
);
var_dump($minValue, $maxValue, $minRow, $maxRow);
- Output for 7.4.0 - 7.4.33, 8.0.1 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
- int(2)
int(43)
array(2) {
["food"]=>
string(9) "tea towle"
["count"]=>
int(2)
}
array(2) {
["food"]=>
string(6) "banana"
["count"]=>
int(43)
}
preferences:
104.49 ms | 407 KiB | 5 Q