3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php $xmls = [6, 3, 2, 5, 4, 1]; echo memory_get_usage() . "\n\n"; usort($xmls, function($a, $b) { static $documents = array(); if (!isset($documents[$a])) { $documents[$a] = true; } if (!isset($documents[$b])) { $documents[$b] = true; } if ($documents[$a] == $documents[$b]) { $result = 0; } else { $result = $documents[$a] < $documents[$b] ? -1 : 1; } echo "a = {$a}, b = {$b}, result = {$result}\n" , memory_get_usage() , "\n" , print_r($documents, true) , "\n"; return $result; }); echo memory_get_usage() . "\n" . print_r($xmls, true) . "\n";
Output for 7.1.0
350064 a = 6, b = 3, result = 0 351592 Array ( [6] => 1 [3] => 1 ) a = 3, b = 2, result = 0 351592 Array ( [6] => 1 [3] => 1 [2] => 1 ) a = 2, b = 5, result = 0 351592 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) a = 5, b = 4, result = 0 351592 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) a = 4, b = 1, result = 0 351592 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350496 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.6 - 7.0.14
350400 a = 6, b = 3, result = 0 351928 Array ( [6] => 1 [3] => 1 ) a = 3, b = 2, result = 0 352056 Array ( [6] => 1 [3] => 1 [2] => 1 ) a = 2, b = 5, result = 0 352056 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) a = 5, b = 4, result = 0 352056 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) a = 4, b = 1, result = 0 352056 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350584 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.0 - 7.0.5
350400 a = 6, b = 3, result = 0 351552 Array ( [6] => 1 [3] => 1 ) a = 3, b = 2, result = 0 351680 Array ( [6] => 1 [3] => 1 [2] => 1 ) a = 2, b = 5, result = 0 351680 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) a = 5, b = 4, result = 0 351680 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) a = 4, b = 1, result = 0 351680 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350584 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 5.6.0 - 5.6.28
223424 a = 2, b = 3, result = 0 224784 Array ( [2] => 1 [3] => 1 ) a = 1, b = 2, result = 0 225448 Array ( [2] => 1 [3] => 1 [1] => 1 ) a = 2, b = 6, result = 0 225584 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) a = 4, b = 2, result = 0 225720 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) a = 5, b = 2, result = 0 225856 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 3, b = 6, result = 0 225856 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 1, b = 5, result = 0 225856 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 4, b = 1, result = 0 225856 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224000 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.5.0 - 5.5.38
223424 a = 2, b = 3, result = 0 224768 Array ( [2] => 1 [3] => 1 ) a = 1, b = 2, result = 0 225432 Array ( [2] => 1 [3] => 1 [1] => 1 ) a = 2, b = 6, result = 0 225568 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) a = 4, b = 2, result = 0 225704 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) a = 5, b = 2, result = 0 225840 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 3, b = 6, result = 0 225840 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 1, b = 5, result = 0 225840 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 4, b = 1, result = 0 225840 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 223984 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.4.10 - 5.4.45
223920 a = 2, b = 3, result = 0 225256 Array ( [2] => 1 [3] => 1 ) a = 1, b = 2, result = 0 225920 Array ( [2] => 1 [3] => 1 [1] => 1 ) a = 2, b = 6, result = 0 226056 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) a = 4, b = 2, result = 0 226192 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) a = 5, b = 2, result = 0 226328 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 3, b = 6, result = 0 226328 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 1, b = 5, result = 0 226328 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 4, b = 1, result = 0 226328 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224480 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.4.0 - 5.4.9
223944 a = 2, b = 3, result = 0 225280 Array ( [2] => 1 [3] => 1 ) a = 1, b = 2, result = 0 225944 Array ( [2] => 1 [3] => 1 [1] => 1 ) a = 2, b = 6, result = 0 226080 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) a = 4, b = 2, result = 0 226216 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) a = 5, b = 2, result = 0 226352 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 3, b = 6, result = 0 226352 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 1, b = 5, result = 0 226352 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) a = 4, b = 1, result = 0 226352 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224504 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/omReZ on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/omReZ on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/omReZ on line 3
Process exited with code 255.