<?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);
preferences:
24.1 ms | 405 KiB | 5 Q