I have array:
$test['name1'][256]=[
'lead_data'=>[
'datum_event'=>'13.03.2019',
'address'=>'addr1'
]
];
$test['name1'][257]=[
'lead_data'=>[
'datum_event'=>'12.02.2019',
'address'=>'addr2'
]
];
$test['name2'][259]=[
'lead_data'=>[
'datum_event'=>'15.03.2019',
'address'=>'addr4'
]
];
$test['name2'][260]=[
'lead_data'=>[
'datum_event'=>'10.03.2019',
'address'=>'addr5'
]
];
$test['name2'][261]=[
'lead_data'=>[
'datum_event'=>'10.02.2019',
'address'=>'addr10'
]
];
I need sort groups 'name1' and 'name2' by the smallest 'datum_event' value . So group 'name2' must be first, bacuse there is the smallest datum_event = '10.02.2019' . Also need sort inner arrays by datum_event (from smallest ti heighest). My code is:
function getMinDate($e) {
return min(array_column(array_column($e, "lead_data"), "datum_event"));
}
uasort($test, function ($a, $b) {return strcmp(getMinDate($b), getMinDate($a));});
foreach($test as &$e) {
uasort($e, function ($a, $b) {
return strcmp($a['lead_data']['datum_event'], $b['lead_data']['datum_event']);});
}
By i cant get correct output, group 'name2' is second, but must be first. Please , how can i solve this?