3v4l.org

run code in 300+ PHP versions simultaneously
<?php $arr = [ [15, 16, 8, 1], [2, 3, 4, 7], [9, 11, 19, 6] ]; function bubbleSortRowCol(&$arr) { $colCount = count($arr[0]); $rowCount = count($arr); $tempArr = []; $columnArr = []; foreach($arr as $key => $value) { if($key % 2 === 0) { $tempArr[$key] = bubbleSortAsc($value); } else { $tempArr[$key] = bubbleSortDesc($value); } } for($i = 0; $i < $colCount; $i++) { $columnArr[$i] = bubbleSort(array_column($tempArr, $i)); } for($i = 0; $i < $rowCount; $i++) { $tempArr[$i] = bubbleSort(array_column($columnArr, $i)); } $arr = $tempArr; } function bubbleSortAsc(array $arr) { $sorted = false; while (false === $sorted) { $sorted = true; for ($i = 0; $i < count($arr)-1; ++$i) { $current = $arr[$i]; $next = $arr[$i+1]; if ($next < $current) { $arr[$i] = $next; $arr[$i+1] = $current; $sorted = false; } } } return $arr; } function bubbleSortDesc(array $arr) { $sorted = false; while (false === $sorted) { $sorted = true; for ($i = 0; $i < count($arr)-1; ++$i) { $current = $arr[$i]; $next = $arr[$i+1]; if ($next > $current) { $arr[$i] = $next; $arr[$i+1] = $current; $sorted = false; } } } return $arr; } function bSort($arr) { bubbleSortRowCol($arr); return $arr; } print_r(bSort($arr));

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.0090.00916.88
8.3.50.0120.00921.98
8.3.40.0070.00718.92
8.3.30.0150.00318.82
8.3.20.0060.00320.13
8.3.10.0040.00423.65
8.3.00.0040.00419.97
8.2.180.0060.00918.67
8.2.170.0070.01122.96
8.2.160.0110.00720.43
8.2.150.0080.00024.18
8.2.140.0050.00324.66
8.2.130.0000.00821.18
8.2.120.0050.00326.35
8.2.110.0060.00320.35
8.2.100.0060.00617.93
8.2.90.0080.00018.95
8.2.80.0040.00417.97
8.2.70.0080.00017.63
8.2.60.0000.00818.05
8.2.50.0030.00518.07
8.2.40.0060.00319.21
8.2.30.0000.00820.65
8.2.20.0040.00417.75
8.2.10.0040.00418.08
8.2.00.0040.00418.09
8.1.280.0110.00425.92
8.1.270.0040.00423.99
8.1.260.0040.00428.09
8.1.250.0040.00428.09
8.1.240.0000.00922.14
8.1.230.0000.01117.78
8.1.220.0060.00317.74
8.1.210.0030.00518.77
8.1.200.0030.00617.35
8.1.190.0090.00017.53
8.1.180.0000.00818.10
8.1.170.0000.01018.65
8.1.160.0040.00420.78
8.1.150.0040.00418.88
8.1.140.0030.00519.61
8.1.130.0000.00717.77
8.1.120.0040.00417.50
8.1.110.0040.00417.44
8.1.100.0000.00717.54
8.1.90.0040.00417.39
8.1.80.0000.00717.52
8.1.70.0060.00317.46
8.1.60.0050.00517.63
8.1.50.0080.00017.54
8.1.40.0030.00617.55
8.1.30.0000.00817.68
8.1.20.0070.00017.57
8.1.10.0080.00017.63
8.1.00.0040.00417.59
8.0.300.0050.00318.77
8.0.290.0040.00416.88
8.0.280.0000.00718.44
8.0.270.0070.00017.21
8.0.260.0060.00017.23
8.0.250.0030.00517.08
8.0.240.0000.00717.09
8.0.230.0070.00017.04
8.0.220.0030.00317.01
8.0.210.0070.00016.96
8.0.200.0030.00317.04
8.0.190.0000.00917.04
8.0.180.0050.00516.87
8.0.170.0000.00816.98
8.0.160.0050.00316.92
8.0.150.0030.00516.93
8.0.140.0040.00716.98
8.0.130.0000.00713.33
8.0.120.0040.00417.00
8.0.110.0000.00717.01
8.0.100.0000.00816.88
8.0.90.0040.00416.87
8.0.80.0100.00716.98
8.0.70.0000.00716.96
8.0.60.0030.00517.05
8.0.50.0000.00716.78
8.0.30.0120.00917.02
8.0.20.0080.01017.40
8.0.10.0050.00217.18
8.0.00.0090.01016.87
7.4.330.0000.00516.79
7.4.320.0000.00716.54
7.4.300.0000.00616.52
7.4.290.0030.00316.67
7.4.280.0070.00416.52
7.4.270.0030.00316.67
7.4.260.0040.00716.50
7.4.250.0040.00416.48
7.4.240.0040.00316.55
7.4.230.0070.00016.61
7.4.220.0110.01116.47
7.4.210.0060.01016.54
7.4.200.0030.00316.52
7.4.160.0100.01016.68
7.4.150.0110.00617.40
7.4.140.0140.00817.86
7.4.130.0040.01416.59
7.4.120.0080.00916.46
7.4.110.0090.01516.45
7.4.100.0120.00916.48
7.4.90.0040.01216.45
7.4.80.0150.01219.39
7.4.70.0120.00916.49
7.4.60.0030.01316.50
7.4.50.0040.01416.47
7.4.40.0120.00816.39
7.4.30.0110.00616.75
7.4.00.0040.01115.24
7.3.330.0020.00513.43
7.3.320.0050.00013.36
7.3.310.0000.00716.45
7.3.300.0070.00016.45
7.3.290.0000.00716.35
7.3.280.0100.00816.42
7.3.270.0060.01317.40
7.3.260.0060.01116.44
7.3.250.0120.00716.43
7.3.240.0100.01116.45
7.3.230.0190.00316.45
7.3.210.0160.00316.58
7.3.200.0080.01216.51
7.3.190.0100.00616.43
7.3.180.0100.01016.66
7.3.170.0150.00416.43
7.3.160.0060.01016.42
7.2.330.0120.00616.47
7.2.320.0030.01416.63
7.2.310.0090.00916.60
7.2.300.0070.01116.68
7.2.290.0120.00616.82
7.2.60.0040.01116.97
7.2.00.0060.00919.46
7.1.200.0150.00615.76
7.1.100.1270.00312.24
7.1.70.0050.00317.02
7.1.60.0150.00919.13
7.1.50.0080.00316.75
7.1.00.0030.07722.46
7.0.200.0030.00516.88
7.0.60.0170.06721.59
7.0.50.0000.04317.97
7.0.40.0030.04720.30
7.0.30.0200.04020.17
7.0.20.0370.07320.23
7.0.10.0130.08320.03
7.0.00.0030.08320.19
5.6.280.0030.03321.13
5.6.210.0030.08720.52
5.6.200.0070.05718.19
5.6.190.0100.07020.55
5.6.180.0230.06020.61
5.6.170.0200.05020.62
5.6.160.0070.07720.50
5.6.150.0000.04718.28
5.6.140.0000.05018.14
5.6.130.0100.05018.24
5.6.120.0070.08721.13
5.6.110.0100.07721.00
5.6.100.0200.06020.99
5.6.90.0000.08721.02
5.6.80.0000.08320.42
5.5.350.0200.06320.48
5.5.340.0100.08017.99
5.5.330.0070.08320.40
5.5.320.0230.04320.27
5.5.310.0300.08320.28
5.5.300.0100.06017.94
5.5.290.0030.08717.98
5.5.280.0070.07720.86
5.5.270.0070.08320.99
5.5.260.0030.06020.86
5.5.250.0070.04320.61
5.5.240.0270.04720.37

preferences:
53.69 ms | 401 KiB | 5 Q