3v4l.org

run code in 300+ PHP versions simultaneously
<?php $array = [ ['name' => 'Dr. Hugo Lopez', 'duty' => 'Anesthesiologist', 'link' => ''], ['name' => 'Dr. Dario Garin', 'duty' => 'Orthopedic Specialist', 'link' => 'dr-dario-garin.php'], ['name' => 'Dr. Maclovio Yañez', 'duty' => 'Plastic Surgeon', 'link' => ''], ['name' => 'Melissa Bracker', 'duty' => 'Patient Liaison', 'link' => ''], ['name' => 'Dr. Diego Guzman', 'duty' => 'Cardiologist', 'link' => ''], ['name' => 'Ivan Arafat', 'duty' => 'Accountant', 'link' => ''], ['name' => 'Jorge Fernandez', 'duty' => 'Hospital Administrator', 'link' => ''], ]; $lookup = array_flip(['Hospital Administrator', 'Plastic Surgeon', 'Orthopedic Specialist']); $fallback = count($lookup); usort($array, function ($a, $b) use ($lookup, $fallback) { $aName = array_reverse(preg_match('~^((?:[a-z]+\.)?) ?(\S+) (.+)~i', $a['name'], $out) ? $out : ['', '', '']); $bName = array_reverse(preg_match('~^((?:[a-z]+\.)?) ?(\S+) (.+)~i', $b['name'], $out) ? $out : ['', '', '']); return [$lookup[$a['duty']] ?? $fallback, ...$aName] <=> [$lookup[$b['duty']] ?? $fallback, ...$bName]; }); var_export($array);
Output for 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.33, 8.2.0 - 8.2.29, 8.3.0 - 8.3.26, 8.4.1 - 8.4.13
array ( 0 => array ( 'name' => 'Jorge Fernandez', 'duty' => 'Hospital Administrator', 'link' => '', ), 1 => array ( 'name' => 'Dr. Maclovio Yañez', 'duty' => 'Plastic Surgeon', 'link' => '', ), 2 => array ( 'name' => 'Dr. Dario Garin', 'duty' => 'Orthopedic Specialist', 'link' => 'dr-dario-garin.php', ), 3 => array ( 'name' => 'Ivan Arafat', 'duty' => 'Accountant', 'link' => '', ), 4 => array ( 'name' => 'Melissa Bracker', 'duty' => 'Patient Liaison', 'link' => '', ), 5 => array ( 'name' => 'Dr. Diego Guzman', 'duty' => 'Cardiologist', 'link' => '', ), 6 => array ( 'name' => 'Dr. Hugo Lopez', 'duty' => 'Anesthesiologist', 'link' => '', ), )
Output for 7.2.0 - 7.2.33, 7.3.0 - 7.3.33
Parse error: syntax error, unexpected '...' (T_ELLIPSIS), expecting ']' in /in/LRuD4 on line 19
Process exited with code 255.

preferences:
153.86 ms | 408 KiB | 5 Q