3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /*function sortByLength($a,$b){ return strlen($b)-strlen($a); } $array = array("bbbbb", "dog", "cat", "aaa", "aaaa"); echo usort($array,'sortByLength'); // print_r($sorted);*/ $priorities = array(5, 8, 3, 7, 3); usort($priorities, function($a, $b) { if ($a == $b) { echo "a ($a) is same priority as b ($b), keeping the same\n"; return 0; } else if ($a > $b) { echo "a ($a) is higher priority than b ($b), moving b down array\n"; return -1; } else { echo "b ($b) is higher priority than a ($a), moving b up array\n"; return 1; } }); echo "Sorted priorities:\n"; var_dump($priorities);
based on 5SSgk
Output for 7.0.0 - 7.2.0
b (8) is higher priority than a (5), moving b up array b (8) is higher priority than a (3), moving b up array a (5) is higher priority than b (3), moving b down array b (7) is higher priority than a (3), moving b up array b (7) is higher priority than a (5), moving b up array a (8) is higher priority than b (7), moving b down array a (3) is same priority as b (3), keeping the same Sorted priorities: array(5) { [0]=> int(8) [1]=> int(7) [2]=> int(5) [3]=> int(3) [4]=> int(3) }
Output for 5.3.18 - 5.6.28
b (8) is higher priority than a (3), moving b up array b (5) is higher priority than a (3), moving b up array b (7) is higher priority than a (3), moving b up array a (3) is same priority as b (3), keeping the same a (8) is higher priority than b (3), moving b down array b (8) is higher priority than a (7), moving b up array b (8) is higher priority than a (5), moving b up array b (8) is higher priority than a (3), moving b up array a (5) is higher priority than b (3), moving b down array a (7) is higher priority than b (5), moving b down array Sorted priorities: array(5) { [0]=> int(8) [1]=> int(7) [2]=> int(5) [3]=> int(3) [4]=> int(3) }