Can someone help me i need to sort this array:
$report_fields['client_id'] = $row['client_id'];
$report_fields['name'] = $row['name'];
$report_fields['is_authorized'] = $row['is_authorized'];
$report_fields['date_created'] = $row['date_created'];
$report_fields['service_id'] = $row['service_id'];
$report_fields['type_id'] = $row['type_id'];
$report_fields['report_name'] = $report_types[$row['type_id']]['type'];
$report_groups[$row['ref_no']][$row['id']] = $report_fields;
I have tried usort like so:
usort($report_groups[$row['ref_no']],'cmp');
function cmp($a,$b) {
$a_stm = strtotime($a["date_created"]);
$b_stm = strtotime($b["date_created"]);
if ($a_stm == $b_stm) {
return 0;
}
return ($a_stm < $b_stm) ? -1 : 1;
}
But the result returned is incorrect.
array_multisort()but if yourref_novalues are numeric, you'll lose them. This question is missing its minimal reproducible example. Implementingusort()is going to be a little more clumsy because you have dynamicidvalues as the second level keys -- so you'd need two function calls on each iteration.