<?php $a = [ 'admin' => [ [ 'id' => 3, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2000-01-01 00:00:00', 'full_link' => 'admin/billing_contacts.app', ], [ 'id' => 1, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-19 13:18:59', 'full_link' => 'admin/billing_contacts.app', ], [ 'id' => 2, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-15 13:18:59', 'full_link' => 'admin/billing_contacts.app', ], ], 'invoice' => [ [ 'id' => 3, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2000-01-01 00:00:00', 'full_link' => 'admin/create_invoice.app', ], [ 'id' => 1, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-19 13:18:59', 'full_link' => 'admin/create_invoice.app', ], [ 'id' => 2, 'user_type' => 'Accountant', 'latest_user_activity_date' => '2018-04-20 13:18:59', 'full_link' => 'admin/create_invoice.app', ], ], ]; function customSort(array $array) { // Iterate through and sort second level array by most recent date foreach ($array as $key => &$value) { usort($value, function ($a, $b) { return strtotime($a['latest_user_activity_date']) < strtotime($b['latest_user_activity_date']) ? 1 : -1; }); } // Sort first level array by date descending of first (most recent) entry uasort($array, function ($a, $b) { return strtotime($a[0]['latest_user_activity_date']) < strtotime($b[0]['latest_user_activity_date']) ? 1 : -1; }); return $array; } print_r(customSort($a));
You have javascript disabled. You will not be able to edit any code.