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) . "\n"; if ($documents[$a] == $documents[$b]) { return 0; } return $documents[$a] < $documents[$b] ? -1 : 1; }); print_r($xmls);
Output for 7.1.0
349176 Array ( [6] => 1 [3] => 1 ) 350704 1 Array ( [6] => 1 [3] => 1 [2] => 1 ) 350704 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 350704 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 350704 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350704 1 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.6 - 7.0.14
349512 Array ( [6] => 1 [3] => 1 ) 351040 1 Array ( [6] => 1 [3] => 1 [2] => 1 ) 351040 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 351040 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 351040 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 351040 1 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.0 - 7.0.5
349512 Array ( [6] => 1 [3] => 1 ) 350664 1 Array ( [6] => 1 [3] => 1 [2] => 1 ) 350664 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 350664 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 350664 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350664 1 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for hhvm-3.10.0 - 3.12.0
2097152 Array ( [6] => 1 [3] => 1 ) 2097152 1 Array ( [6] => 1 [3] => 1 [2] => 1 ) 2097152 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 2097152 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 2097152 1 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 2097152 1 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 5.6.7 - 5.6.28
222264 Array ( [2] => 1 [3] => 1 ) 223600 1 Array ( [2] => 1 [3] => 1 [1] => 1 ) 223736 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 223872 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 224008 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224144 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224144 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224144 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224144 1 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.5.24 - 5.5.35
222264 Array ( [2] => 1 [3] => 1 ) 223560 1 Array ( [2] => 1 [3] => 1 [1] => 1 ) 223696 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 223832 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 223968 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224104 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224104 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224104 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224104 1 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.4.0 - 5.4.45
222784 Array ( [2] => 1 [3] => 1 ) 224072 1 Array ( [2] => 1 [3] => 1 [1] => 1 ) 224208 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 224344 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 224480 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224616 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224616 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224616 1 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 224616 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/C1tFh 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/C1tFh on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/C1tFh on line 3
Process exited with code 255.