3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = array( array( "name" => "SomeName1", "type" => "A"), array( "name" => "SomeName2", "type" => "A"), array( "name" => "SomeName3", "type" => "A"), array( "name" => "SomeName4", "type" => "A"), array( "name" => "SomeName5", "type" => "A"), array( "name" => "SomeName6", "type" => "B"), array( "name" => "SomeName7", "type" => "B"), array( "name" => "SomeName8", "type" => "B"), array( "name" => "SomeName9", "type" => "C"), array( "name" => "SomeName0", "type" => "C") ); $dataSorted = array(); $counts = array(); foreach($data as $elem) { // just init values for a new type if(!isset($counts[$elem['type']])) { $counts[$elem['type']] = 0; $dataByType[$elem['type']] = array(); } // count types $counts[$elem['type']]++; // save it to grouped array $dataByType[$elem['type']][] = $elem; } // sort it to A=>5, B=>3 C=>2 arsort($counts, SORT_NUMERIC); // get sorted types as an array $types = array_keys($counts); // index will be looped 0 -> count($types) - 1 and then down to 0 again $currentTypeIndex = 0; // make a walk on sorted array. First get the most popular, then less popular etc. // when all types are added, repeat while(count($dataSorted) < count($data)) { $currentType = $types[$currentTypeIndex]; // skip adding if we ran out this type if($counts[$currentType]) { // pop an element of selected type $dataSorted[] = array_pop($dataByType[$currentType]); // decrease counter $counts[$currentType]--; } // choose next type $currentTypeIndex = (++$currentTypeIndex)%count($types); } print_r($dataSorted);

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.3.60.0110.00718.30
8.3.50.0090.00922.94
8.3.40.0110.00418.92
8.3.30.0090.00618.84
8.3.20.0050.00221.89
8.3.10.0050.00220.20
8.3.00.0000.00819.85
8.2.180.0070.01118.16
8.2.170.0110.00322.96
8.2.160.0070.00720.45
8.2.150.0060.00324.18
8.2.140.0040.00424.66
8.2.130.0090.00626.16
8.2.120.0080.00019.96
8.2.110.0080.00020.52
8.2.100.0080.00417.84
8.2.90.0050.00319.30
8.2.80.0080.00017.97
8.2.70.0050.00317.50
8.2.60.0050.00318.04
8.2.50.0050.00319.25
8.2.40.0060.00320.65
8.2.30.0020.00519.26
8.2.20.0000.00818.07
8.2.10.0050.00318.14
8.2.00.0080.00017.81
8.1.280.0060.01325.92
8.1.270.0000.00722.16
8.1.260.0080.00026.35
8.1.250.0000.00828.09
8.1.240.0080.00023.92
8.1.230.0090.00317.84
8.1.220.0000.00917.74
8.1.210.0050.00318.77
8.1.200.0090.00017.13
8.1.190.0050.00317.23
8.1.180.0040.00418.10
8.1.170.0000.00818.50
8.1.160.0000.00722.27
8.1.150.0000.00722.03
8.1.140.0070.00019.60
8.1.130.0030.00318.97
8.1.120.0070.00017.51
8.1.110.0030.00517.48
8.1.100.0000.00717.48
8.1.90.0030.00517.51
8.1.80.0000.00717.47
8.1.70.0000.00717.39
8.1.60.0000.00817.61
8.1.50.0080.00017.53
8.1.40.0050.00317.46
8.1.30.0030.00517.59
8.1.20.0040.00417.68
8.1.10.0030.00517.63
8.1.00.0000.00917.44
8.0.300.0080.00318.77
8.0.290.0000.00816.75
8.0.280.0070.00018.52
8.0.270.0030.00316.90
8.0.260.0080.00017.13
8.0.250.0030.00316.91
8.0.240.0060.00316.99
8.0.230.0070.00016.97
8.0.220.0000.00716.80
8.0.210.0030.00316.82
8.0.200.0040.00416.88
8.0.190.0030.00616.84
8.0.180.0080.00016.97
8.0.170.0030.00316.93
8.0.160.0030.00616.84
8.0.150.0030.00516.79
8.0.140.0030.00516.76
8.0.130.0040.00313.42
8.0.120.0000.00716.77
8.0.110.0030.00316.84
8.0.100.0040.00416.71
8.0.90.0040.00416.85
8.0.80.0100.00716.97
8.0.70.0040.00416.95
8.0.60.0000.00816.92
8.0.50.0050.00216.98
8.0.30.0100.00817.13
8.0.20.0090.01017.40
8.0.10.0000.00716.98
8.0.00.0150.00316.91
7.4.330.0050.00015.55
7.4.320.0030.00316.64
7.4.300.0030.00316.53
7.4.290.0000.00816.62
7.4.280.0040.00416.41
7.4.270.0030.00316.51
7.4.260.0030.00316.52
7.4.250.0030.00316.50
7.4.240.0080.00016.63
7.4.230.0070.00016.69
7.4.220.0130.00316.50
7.4.210.0030.01616.54
7.4.200.0000.00716.50
7.4.160.0110.00516.56
7.4.150.0040.01317.40
7.4.140.0090.00917.86
7.4.130.0110.00816.61
7.4.120.0100.00916.54
7.4.110.0200.00316.51
7.4.100.0060.01116.52
7.4.90.0100.01616.43
7.4.80.0060.01019.39
7.4.70.0120.00616.56
7.4.60.0100.00616.53
7.4.50.0090.00216.48
7.4.40.0080.00816.31
7.4.30.0060.01016.30
7.4.00.0130.00514.99
7.3.330.0000.00613.08
7.3.320.0050.00013.16
7.3.310.0040.00416.39
7.3.300.0070.00016.23
7.3.290.0070.00716.34
7.3.280.0110.00816.33
7.3.270.0060.01017.40
7.3.260.0120.00616.52
7.3.250.0080.00916.42
7.3.240.0060.01216.59
7.3.230.0100.00716.29
7.3.210.0070.01016.56
7.3.200.0130.00316.48
7.3.190.0100.00716.35
7.3.180.0120.00316.26
7.3.170.0140.00316.34
7.3.160.0060.01516.32
7.3.120.0040.01114.93
7.3.110.0060.01014.65
7.3.100.0050.00914.81
7.3.90.0020.00714.92
7.3.80.0060.00914.85
7.3.70.0080.00314.55
7.3.60.0050.00714.62
7.3.50.0040.01014.92
7.3.40.0070.00814.83
7.3.30.0030.00914.72
7.3.20.0030.00916.79
7.3.10.0040.00816.63
7.3.00.0070.00816.66
7.2.330.0070.01316.66
7.2.320.0060.01516.55
7.2.310.0070.01016.50
7.2.300.0180.00416.72
7.2.290.0030.01316.75
7.2.250.0120.00615.10
7.2.240.0060.00915.28
7.2.230.0050.01015.20
7.2.220.0030.00915.29
7.2.210.0050.00915.00
7.2.200.0060.00715.12
7.2.190.0050.00915.03
7.2.180.0070.00615.01
7.2.170.0080.00415.07
7.2.160.0030.00614.80
7.2.150.0030.01016.79
7.2.140.0040.00716.87
7.2.130.0080.00316.87
7.2.120.0070.00916.84
7.2.110.0030.01116.93
7.2.100.0060.00916.89
7.2.90.0080.01016.88
7.2.80.0080.00717.03
7.2.70.0070.01017.05
7.2.60.0060.00916.81
7.2.50.0070.00716.90
7.2.40.0050.00516.70
7.2.30.0030.01016.90
7.2.20.0080.00516.90
7.2.10.0060.00917.03
7.2.00.0040.00717.67
7.1.330.0060.00815.70
7.1.320.0040.00715.84
7.1.310.0080.00615.76
7.1.300.0050.00915.77
7.1.290.0030.00615.85
7.1.280.0040.00815.75
7.1.270.0070.00515.81
7.1.260.0070.00715.83
7.1.250.0040.00515.90
7.1.240.0060.00315.83
7.1.230.0130.00715.71
7.1.220.0070.00715.75
7.1.210.0040.00715.42
7.1.200.0050.01015.75
7.1.190.0060.00615.41
7.1.180.0030.00815.70
7.1.170.0090.00615.77
7.1.160.0080.00815.42
7.1.150.0000.01215.79
7.1.140.0030.01015.66
7.1.130.0080.01315.53
7.1.120.0140.00315.98
7.1.110.0130.00315.82
7.1.100.0020.01117.12
7.1.90.0000.01315.75
7.1.80.0060.00615.81
7.1.70.0020.01116.49
7.1.60.0050.00916.49
7.1.50.0070.01016.31
7.1.40.0040.00816.18
7.1.30.0030.00716.31
7.1.20.0030.00716.18
7.1.10.0050.00816.16
7.1.00.0050.00616.29
7.0.330.0040.01515.16
7.0.320.0100.00615.03
7.0.310.0130.00315.14
7.0.300.0060.00915.20
7.0.290.0150.00315.20
7.0.280.0030.01115.14
7.0.270.0120.00015.02
7.0.260.0030.01015.34
7.0.250.0070.00315.09
7.0.240.0180.00415.34
7.0.230.0110.00414.74
7.0.220.0100.00615.00
7.0.210.0040.00415.30
7.0.200.0090.00315.99
7.0.190.0080.00416.11
7.0.180.0060.00615.80
7.0.170.0030.00815.79
7.0.160.0080.00315.86
7.0.150.0000.01115.86
7.0.140.0000.01215.67
7.0.130.0060.00615.91
7.0.120.0030.00815.90
7.0.110.0070.00115.79
7.0.100.0080.00615.72
7.0.90.0060.00615.69
7.0.80.0050.00315.79
7.0.70.0080.00815.78
7.0.60.0050.00915.75
7.0.50.0070.00315.76
7.0.40.0030.01013.86
7.0.30.0090.00213.97
7.0.20.0010.00813.77
7.0.10.0030.00713.87
7.0.00.0030.00713.86
5.6.380.0060.00614.57

preferences:
52.46 ms | 401 KiB | 5 Q