I trying to get the minimum values from the any column contains \"xx\" in the column name.
Below is my code:
foreach()
loop or array_walk()
.id
(first element) value with array_shift()
.min()
on the remaining values in the respective subarray to determine the lowest value.No conditional expressions. No unnecessary variables. Clean, concise, and effective.
Code: (Demo)
$array = [
['id' => 1, '10xx' => 14, '11xx' => 32, '12xx' => 4],
['id' => 2, '10xx' => 13, '11xx' => 36, '12xx' => 41]
];
array_walk($array, function($row) {
echo array_shift($row) , " : " , min($row) , "\n";
});
Output:
1 : 4
2 : 13