This solution is for usort() with an easy-to-remember notation for multidimensional sorting. The spaceship operator <=> is used, which is available from PHP 7.
usort($in,function($a,$b){ return $a['first'] <=> $b['first'] //first asc ?: $a['second'] <=> $b['second'] //second asc ?: $b['third'] <=> $a['third'] //third desc (a b swapped!) //etc ; });
Examples:
$in = [ ['firstname' => 'Anton', 'surname' => 'Gruber', 'birthdate' => '03.08.1967', 'rank' => 3], ['firstname' => 'Anna', 'surname' => 'Egger', 'birthdate' => '04.01.1960', 'rank' => 1], ['firstname' => 'Paul', 'surname' => 'Mueller', 'birthdate' => '15.10.1971', 'rank' => 2], ['firstname' => 'Marie', 'surname' => 'Schmidt ', 'birthdate' => '24.12.1963', 'rank' => 2], ['firstname' => 'Emma', 'surname' => 'Mueller', 'birthdate' => '23.11.1969', 'rank' => 2], ];
First task: Order By rank asc, surname asc
usort($in,function($a,$b){ return $a['rank'] <=> $b['rank'] //first asc ?: $a['surname'] <=> $b['surname'] //second asc ; });
Second task: Order By rank desc, surname asc, firstmame asc
usort($in,function($a,$b){ return $b['rank'] <=> $a['rank'] //first desc ?: $a['surname'] <=> $b['surname'] //second asc ?: $a['firstname'] <=> $b['firstname'] //third asc ; });
Third task: Order By rank desc, birthdate asc
The date cannot be sorted in this notation. It is converted with strtotime.
usort($in,function($a,$b){ return $b['rank'] <=> $a['rank'] //first desc ?: strtotime($a['birthdate']) <=> strtotime($b['birthdate']) //second asc ; });
array_multisort(array_column($array, 'order'), SORT_ASC, $array);