3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ 'c' => [ 'confidence' => 0.999, 'name' => 'not_valid.png', ], 'a' => [ 'confidence' => 0.999, 'name' => 'valid.png', ], 'b' => [ 'confidence' => 0.98, 'name' => 'valid.png', ], 'd' => [ 'confidence' => 0.98, 'name' => 'not_valid.png', ], ]; uasort($data, function (array $a, array $b) { if (array_key_exists('name', $a) && $a['name'] != 'not_valid.png') { if (array_key_exists('name', $b) && $b['name'] != 'not_valid.png') { if ($a['confidence'] == $b['confidence']) { return 0; } return $a['confidence'] > $b['confidence'] ? -1 : 1; } return -1; } else if (array_key_exists('name', $b) && $b['name'] != 'not_valid.png') { return 1; } if ($a['confidence'] == $b['confidence']) { return 0; } return $a['confidence'] > $b['confidence'] ? -1 : 1; }); var_dump($data);
Output for 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.4, 8.3.6 - 8.3.7
array(4) { ["a"]=> array(2) { ["confidence"]=> float(0.999) ["name"]=> string(9) "valid.png" } ["b"]=> array(2) { ["confidence"]=> float(0.98) ["name"]=> string(9) "valid.png" } ["c"]=> array(2) { ["confidence"]=> float(0.999) ["name"]=> string(13) "not_valid.png" } ["d"]=> array(2) { ["confidence"]=> float(0.98) ["name"]=> string(13) "not_valid.png" } }
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0 array(4) { ["a"]=> array(2) { ["confidence"]=> float(0.999) ["name"]=> string(9) "valid.png" } ["b"]=> array(2) { ["confidence"]=> float(0.98) ["name"]=> string(9) "valid.png" } ["c"]=> array(2) { ["confidence"]=> float(0.999) ["name"]=> string(13) "not_valid.png" } ["d"]=> array(2) { ["confidence"]=> float(0.98) ["name"]=> string(13) "not_valid.png" } }

preferences:
265.64 ms | 403 KiB | 289 Q