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; }); echo memory_get_usage() . "\n" . print_r($xmls, true) . "\n";
Output for 7.1.0
349600 351128 Array ( [6] => 1 [3] => 1 ) 351128 Array ( [6] => 1 [3] => 1 [2] => 1 ) 351128 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 351128 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 351128 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350032 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.6 - 7.0.14
349920 351448 Array ( [6] => 1 [3] => 1 ) 351576 Array ( [6] => 1 [3] => 1 [2] => 1 ) 351576 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 351576 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 351576 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350104 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 7.0.0 - 7.0.5
349920 351072 Array ( [6] => 1 [3] => 1 ) 351200 Array ( [6] => 1 [3] => 1 [2] => 1 ) 351200 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 ) 351200 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 ) 351200 Array ( [6] => 1 [3] => 1 [2] => 1 [5] => 1 [4] => 1 [1] => 1 ) 350104 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 ) 2097152 Array ( [0] => 6 [1] => 3 [2] => 2 [3] => 5 [4] => 4 [5] => 1 )
Output for 5.6.0 - 5.6.28
222784 224120 Array ( [2] => 1 [3] => 1 ) 224784 Array ( [2] => 1 [3] => 1 [1] => 1 ) 224920 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 225056 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 225192 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225192 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225192 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225192 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 223360 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.5.0 - 5.5.38
222784 224080 Array ( [2] => 1 [3] => 1 ) 224744 Array ( [2] => 1 [3] => 1 [1] => 1 ) 224880 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 225016 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 225152 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225152 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225152 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225152 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 223344 Array ( [0] => 4 [1] => 1 [2] => 5 [3] => 2 [4] => 3 [5] => 6 )
Output for 5.4.0 - 5.4.45
223304 224592 Array ( [2] => 1 [3] => 1 ) 225256 Array ( [2] => 1 [3] => 1 [1] => 1 ) 225392 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 ) 225528 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 ) 225664 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225664 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225664 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 225664 Array ( [2] => 1 [3] => 1 [1] => 1 [6] => 1 [4] => 1 [5] => 1 ) 223864 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/vWlom 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/vWlom on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/vWlom on line 3
Process exited with code 255.