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; } echo memory_get_usage() . "\n" . print_r($documents, true) . "\n"; if ($documents[$a] == $documents[$b]) { return 0; } return $documents[$a] < $documents[$b] ? -1 : 1; }); print_r($xmls);
Output for 7.1.0
349176 350704 Array ( [6] => 1 [3] => 1 ) 350704 Array ( [6] => 1 [3] => 1 [2] => 1 ) 350704 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 350704 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 350704 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.6 - 7.0.14
349512 351040 Array ( [6] => 1 [3] => 1 ) 351168 Array ( [6] => 1 [3] => 1 [2] => 1 ) 351168 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 351168 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 351168 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.0 - 7.0.5
349512 350664 Array ( [6] => 1 [3] => 1 ) 350792 Array ( [6] => 1 [3] => 1 [2] => 1 ) 350792 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 350792 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 350792 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for hhvm-3.10.0 - 3.12.0
2097152 2097152 Array ( [6] => 1 [3] => 1 ) 2097152 Array ( [6] => 1 [3] => 1 [2] => 1 ) 2097152 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 2097152 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 2097152 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 5.6.0 - 5.6.28
222352 223688 Array ( [2] => 1 [3] => 1 ) 224352 Array ( [2] => 1 [3] => 1 [1] => 1 ) 224488 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 224624 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 224760 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224760 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224760 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224760 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.5.0 - 5.5.38
222352 223672 Array ( [2] => 1 [3] => 1 ) 224336 Array ( [2] => 1 [3] => 1 [1] => 1 ) 224472 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 224608 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 224744 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224744 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224744 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224744 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.4.0 - 5.4.45
222872 224160 Array ( [2] => 1 [3] => 1 ) 224824 Array ( [2] => 1 [3] => 1 [1] => 1 ) 224960 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 225096 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 225232 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225232 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225232 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225232 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 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/opcV6 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/opcV6 on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/opcV6 on line 3
Process exited with code 255.