<?php
$values = json_decode('{
"category": {
"A": [
{
"teacher": 27,
"quantity": 32
},
{
"teacher": 31,
"quantity": 39
},
{
"teacher": 41,
"quantity": 22
},
{
"teacher": 73,
"quantity": 15
}
],
"B": [
{
"teacher": 28,
"quantity": 33
},
{
"teacher": 46,
"quantity": 23
},
{
"teacher": 34,
"quantity": 22
},
{
"teacher": 131,
"quantity": 319
}
],
"C": [
{
"teacher": 72,
"quantity": 139
},
{
"teacher": 88,
"quantity": 12
},
{
"teacher": 83,
"quantity": 56
},
{
"teacher": 55,
"quantity": 23
}
],
"D": [
{
"teacher": 11,
"quantity": 78
},
{
"teacher": 34,
"quantity": 25
},
{
"teacher": 21,
"quantity": 35
},
{
"teacher": 34,
"quantity": 26
}
],
"E": [
{
"teacher": 30,
"quantity": 10
},
{
"teacher": 23,
"quantity": 99
},
{
"teacher": 67,
"quantity": 87
},
{
"teacher": 10,
"quantity": 53
}
]
}
}', true);
$maxQuantity = [];
foreach($values['category'] as $categoryKey => $categoryValues) {
$max = 0;
foreach($categoryValues as $key => $value) {
if($value['quantity'] > $max) {
$max = $value['quantity'];
$maxQuantity[$categoryKey] = $value;
}
}
}
echo "В катеогории А победил " . $maxQuantity['A']['teacher'] . " со счётом " . $maxQuantity['A']['quantity'] . ".\n";
var_dump($maxQuantity);