3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Assume that this is the data that we get back from get_users or a similar function $users = array( 0 => array( 'name' => 'Tom', 'payments' => array( 0 => array( 'date' => '2020-04-15', 'amount' => '750', ), 1 => array( 'date' => '2020-04-20', 'amount' => '900', ), ), ), 1 => array( 'name' => 'Dick', 'payments' => array( 0 => array( 'date' => '2020-04-10', 'amount' => '750', ), 1 => array( 'date' => '2020-04-15', 'amount' => '900', ), 2 => array( 'date' => '2020-04-25', 'amount' => '1250', ), ), ), 2 => array( 'name' => 'Harry', 'payments' => array( 0 => array( 'date' => '2020-04-24', 'amount' => '750', ), ), ), ); function sort_users_by_date( $user1, $user2 ) { $date1 = end($user1['payments'])['date']; $date2 = end($user2['payments'])['date']; return strtotime($date2) - strtotime($date1); } usort($users, 'sort_users_by_date'); var_dump($users);
based on OW38t
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.21, 7.4.0 - 7.4.9, 8.0.0alpha1 - beta1
array(3) { [0]=> array(2) { ["name"]=> string(4) "Dick" ["payments"]=> array(3) { [0]=> array(2) { ["date"]=> string(10) "2020-04-10" ["amount"]=> string(3) "750" } [1]=> array(2) { ["date"]=> string(10) "2020-04-15" ["amount"]=> string(3) "900" } [2]=> array(2) { ["date"]=> string(10) "2020-04-25" ["amount"]=> string(4) "1250" } } } [1]=> array(2) { ["name"]=> string(5) "Harry" ["payments"]=> array(1) { [0]=> array(2) { ["date"]=> string(10) "2020-04-24" ["amount"]=> string(3) "750" } } } [2]=> array(2) { ["name"]=> string(3) "Tom" ["payments"]=> array(2) { [0]=> array(2) { ["date"]=> string(10) "2020-04-15" ["amount"]=> string(3) "750" } [1]=> array(2) { ["date"]=> string(10) "2020-04-20" ["amount"]=> string(3) "900" } } } }