3v4l.org

run code in 300+ PHP versions simultaneously
<?php function sanitizeColumnReference($row, $columnReference) { if (!isset($row[$columnReference]) && is_int($columnReference)) { $columnReference = array_keys($row)[$columnReference] ?? null; // attempt to derive column name by position if ($columnReference === null) { throw new Exception('Failed to locate column by position using column reference: ' . $columnReference); } } return $columnReference; } function dynamicSort(&$input, $sortingRules) { if (!$input || !$sortingRules || !is_array($input) || !is_array($sortingRules)) { return; // return silently } $firstRow = current($input); $sortingParams = []; foreach ($sortingRules as $rule) { $rule = (array)$rule; // permit the passing of a solitary string as a sorting rule $columnReference = sanitizeColumnReference($firstRow, array_shift($rule)); $column = array_column($input, $columnReference); if (!$column) { throw new Exception('Failed to source sortable data from column reference: ' . $columnReference); } $sortingParams[] = $column; foreach ($rule as $flag) { $sortingParams[] = constant('SORT_' . strtoupper($flag)); // convert strings to usable CONSTANTs } } $sortingParams[] = &$input; var_export($sortingParams); array_multisort(...$sortingParams); // unpack into native sorting function } $array = [ ['first_name' => 'Homer', 'last_name' => 'Simpson', 'city' => 'Springfield', 'state' => 'Unknown', 'zip' => '66735'], ['first_name' => 'Patty', 'last_name' => 'Bouvier', 'city' => 'Scottsdale', 'state' => 'Arizona', 'zip' => '85250'], ['first_name' => 'Moe', 'last_name' => 'Szyslak', 'city' => 'Scottsdale', 'state' => 'Arizona', 'zip' => '85255'], ['first_name' => 'Nick', 'last_name' => 'Riviera', 'city' => 'Scottsdale', 'state' => 'Arizona', 'zip' => '85255'], ]; $sortingRules = [ 'city', ['zip', 'desc', 'numeric'], [1, 'desc'], // last_name ]; echo "Sorting Params:\n"; dynamicSort($array, $sortingRules); // this modifies by reference like native sorting functions echo "\n---\nOutput:\n"; var_export($array);

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.4.130.0060.00418.63
8.4.120.0120.00724.26
8.4.110.0100.00820.46
8.4.100.0120.00818.02
8.4.90.0140.00620.55
8.4.80.0060.00218.86
8.4.70.0110.01018.95
8.4.60.0100.00919.04
8.4.50.0120.00720.71
8.4.40.0070.01417.93
8.4.30.0040.00418.53
8.4.20.0100.01019.60
8.4.10.0070.01119.32
8.3.260.0100.00916.51
8.3.250.0120.00819.16
8.3.240.0130.00617.05
8.3.230.0140.00716.71
8.3.220.0110.00719.10
8.3.210.0050.00416.90
8.3.200.0050.00416.75
8.3.190.0090.01217.06
8.3.180.0120.00618.34
8.3.170.0030.00517.18
8.3.160.0150.00618.51
8.3.150.0100.01019.17
8.3.140.0120.00316.71
8.3.130.0140.00418.29
8.3.120.0000.00920.55
8.3.110.0100.00617.64
8.3.100.0220.01020.30
8.3.90.0220.00821.63
8.3.80.0210.01116.55
8.3.70.0230.01216.80
8.3.60.0240.01216.51
8.3.50.0190.00921.71
8.3.40.0190.01218.14
8.3.30.0120.01418.15
8.3.20.0170.00320.78
8.3.10.0190.00321.00
8.3.00.0110.00522.63
8.2.290.0070.00320.28
8.2.280.0110.00818.55
8.2.270.0100.01019.09
8.2.260.0090.00617.33
8.2.250.0000.00916.87
8.2.240.0040.00417.57
8.2.230.0210.00918.56
8.2.220.0150.00827.08
8.2.210.0190.00621.52
8.2.200.0200.00416.56
8.2.190.0220.00516.53
8.2.180.0180.00521.16
8.2.170.0200.00618.29
8.2.160.0250.00320.28
8.2.150.0240.00321.60
8.2.140.0200.00321.10
8.2.130.0240.00321.81
8.2.120.0180.00419.19
8.2.110.0190.00319.74
8.2.100.0210.00518.54
8.2.90.0150.01017.73
8.2.80.0140.00918.11
8.2.70.0120.01117.52
8.2.60.0180.00317.68
8.2.50.0180.00417.78
8.2.40.0140.00818.62
8.2.30.0130.00717.81
8.2.20.0130.00717.75
8.2.10.0110.00918.44
8.2.00.0140.00618.26
8.1.330.0110.00721.95
8.1.320.0100.00917.94
8.1.310.0070.01018.25
8.1.300.0080.00818.34
8.1.290.0070.00817.58
8.1.280.0130.00421.05
8.1.270.0110.00320.70
8.1.260.0170.00121.81
8.1.250.0160.00322.59
8.1.240.0100.00419.67
8.1.230.0090.00717.60
8.1.220.0080.00617.56
8.1.210.0070.00617.95
8.1.200.0070.00717.21
8.1.190.0090.00417.15
8.1.180.0090.00317.57
8.1.170.0050.00917.96
8.1.160.0120.00218.05
8.1.150.0070.00718.11
8.1.140.0100.00417.99
8.1.130.0100.00317.37
8.1.120.0080.00617.34
8.1.110.0100.00317.36
8.1.100.0110.00217.33
8.1.90.0070.00517.25
8.1.80.0070.00717.37
8.1.70.0070.00517.31
8.1.60.0080.00617.40
8.1.50.0080.00617.32
8.1.40.0100.00317.46
8.1.30.0110.00317.47
8.1.20.0100.00617.48
8.1.10.0110.00317.49
8.1.00.0110.00317.38
8.0.300.0160.00417.71
8.0.290.0140.00616.71
8.0.280.0150.00817.47
8.0.270.0170.00517.05
8.0.260.0140.00516.62
8.0.250.0200.00216.74
8.0.240.0150.00316.82
8.0.230.0110.00816.71
8.0.220.0100.00916.63
8.0.210.0120.01016.85
8.0.200.0130.00716.85
8.0.190.0150.00516.82
8.0.180.0150.00816.79
8.0.170.0160.00816.74
8.0.160.0180.00616.68
8.0.150.0160.00816.66
8.0.140.0120.00516.69
8.0.130.0160.00414.79
8.0.120.0160.00316.55
8.0.110.0070.01016.74
8.0.100.0080.00416.72
8.0.90.0130.00616.59
8.0.80.0090.01016.76
8.0.70.0100.00316.73
8.0.60.0130.00616.69
8.0.50.0090.00316.68
8.0.30.0080.00916.88
8.0.20.0150.01216.88
8.0.10.0130.00816.95
8.0.00.0140.00816.72
7.4.330.0080.00515.86
7.4.320.0200.00516.33
7.4.300.0090.00316.38
7.4.290.0160.00616.43
7.4.280.0100.00916.42
7.4.270.0140.00516.48
7.4.260.0090.00314.82
7.4.250.0080.00316.43
7.4.240.0110.00616.46
7.4.230.0130.00216.41
7.4.220.0100.00516.42
7.4.210.0110.00816.53
7.4.200.0100.00516.40
7.4.190.0210.00016.30
7.4.180.0260.00516.18
7.4.160.0190.00416.35
7.4.150.0210.00216.18
7.4.140.0160.00716.23
7.4.130.0090.01416.47
7.4.120.0170.00916.35
7.4.110.0130.01016.37
7.4.100.0150.00416.46
7.4.90.0100.00816.35
7.4.80.0070.00917.79
7.4.70.0230.00616.46
7.4.60.0120.01616.39
7.4.50.0170.00416.39
7.4.40.0170.00616.41
7.4.30.0180.01016.34
7.4.20.0180.01016.32
7.4.10.0160.01116.33
7.4.00.0190.00816.51
7.3.330.0190.00316.21
7.3.320.0150.00614.78
7.3.310.0180.00316.35
7.3.300.0120.00816.20
7.3.290.0110.00816.33
7.3.280.0170.00716.29
7.3.270.0200.00816.18
7.3.260.0140.00916.46
7.3.250.0190.00816.21
7.3.240.0100.01216.35
7.3.230.0160.00916.28
7.3.220.0230.01016.18
7.3.210.0180.00816.38
7.3.200.0180.00416.35
7.3.190.0160.01016.24
7.3.180.0180.00916.28
7.3.170.0190.01216.32
7.3.160.0170.00816.40
7.3.150.0170.00916.29
7.3.140.0210.00616.26
7.3.130.0190.00816.36
7.3.120.0220.00516.34
7.3.110.0220.00616.32
7.3.100.0110.01416.38
7.3.90.0210.00616.28
7.3.80.0180.00816.27
7.3.70.0180.00516.31
7.3.60.0160.00716.34
7.3.50.0160.00916.33
7.3.40.0130.00916.25
7.3.30.0140.00816.26
7.3.20.0170.01017.21
7.3.10.0120.01517.26
7.3.00.0260.00417.16
7.2.340.0300.00016.29
7.2.330.0180.00816.35
7.2.320.0170.00916.52
7.2.310.0120.01416.49
7.2.300.0160.00916.42
7.2.290.0200.00616.47
7.2.280.0170.01016.37
7.2.270.0190.00716.42
7.2.260.0210.00516.48
7.2.250.0180.01116.44
7.2.240.0140.01016.37
7.2.230.0210.00616.31
7.2.220.0150.01116.57
7.2.210.0140.01016.55
7.2.200.0170.01116.59
7.2.190.0220.01016.46
7.2.180.0170.01016.44
7.2.170.0190.00716.55
7.2.160.0160.00916.62
7.2.150.0220.00917.44
7.2.140.0220.00517.42
7.2.130.0340.01117.43
7.2.120.0160.01017.46
7.2.110.0170.00917.43
7.2.100.0170.01117.38
7.2.90.0210.00817.44
7.2.80.0180.00817.35
7.2.70.0200.00517.51
7.2.60.0150.01017.52
7.2.50.0170.01017.46
7.2.40.0230.00817.52
7.2.30.0240.00517.43
7.2.20.0130.00817.52
7.2.10.0220.00417.65
7.2.00.0150.00617.55
7.1.330.0220.00317.11
7.1.320.0220.00017.02
7.1.310.0200.00517.05
7.1.300.0140.01017.08
7.1.290.0120.00817.02
7.1.280.0210.00317.15
7.1.270.0200.00316.91
7.1.260.0100.00517.20
7.1.250.0100.00516.93
7.1.240.0110.00317.13
7.1.230.0250.00617.06
7.1.220.0220.00816.81
7.1.210.0220.00816.70
7.1.200.0300.00517.12
7.1.190.0340.00016.96
7.1.180.0200.01016.98
7.1.170.0220.00717.04
7.1.160.0240.00716.99
7.1.150.0230.00817.10
7.1.140.0230.00816.93
7.1.130.0300.00016.73
7.1.120.0240.00617.18
7.1.110.0200.01217.08
7.1.100.0270.01716.86
7.1.90.0190.01017.03
7.1.80.0220.00316.94
7.1.70.0170.00816.88
7.1.60.0260.00417.17
7.1.50.0220.00317.06
7.1.40.0230.00717.14
7.1.30.0200.01017.11
7.1.20.0180.01217.26
7.1.10.0210.00917.32
7.1.00.0280.00317.07
7.0.330.0260.00416.84
7.0.320.0260.00316.73
7.0.310.0230.00916.52
7.0.300.0210.00816.68
7.0.290.0230.00616.95
7.0.280.0190.01416.66
7.0.270.0300.00416.80
7.0.260.0200.01516.75
7.0.250.0290.00016.81
7.0.240.0270.00016.77
7.0.230.0270.00316.64
7.0.220.0230.00916.56
7.0.210.0140.00816.98
7.0.200.0100.00316.96
7.0.190.0290.00016.84
7.0.180.0210.00917.02
7.0.170.0220.00716.75
7.0.160.0260.00416.62
7.0.150.0230.01016.72
7.0.140.0260.00316.92
7.0.130.0220.00716.92
7.0.120.0220.00717.12
7.0.110.0210.00716.77
7.0.100.0190.01017.00
7.0.90.0260.00316.61
7.0.80.0120.01616.61
7.0.70.0250.00816.73
7.0.60.0210.00916.80
7.0.50.0230.00816.54
7.0.40.0290.00316.89
7.0.30.0240.00716.71
7.0.20.0250.00416.66
7.0.10.0220.00316.82
7.0.00.0260.00416.78
5.6.400.0230.00816.18
5.6.390.0290.00316.18
5.6.380.0220.00616.18
5.6.370.0260.00316.18
5.6.360.0230.00616.18
5.6.350.0230.00616.18
5.6.340.0220.00816.18
5.6.330.0270.00316.18
5.6.320.0200.01016.18
5.6.310.0290.00416.18
5.6.300.0230.01016.18
5.6.290.0200.00716.18
5.6.280.0230.00416.18
5.6.270.0220.00616.18
5.6.260.0260.00316.18
5.6.250.0180.00616.18
5.6.240.0270.00316.18
5.6.230.0170.00816.18
5.6.220.0270.00016.18
5.6.210.0220.00716.18
5.6.200.0210.00816.18
5.6.190.0170.00916.18
5.6.180.0230.00816.18
5.6.170.0250.00316.18
5.6.160.0200.00416.18
5.6.150.0090.00916.18
5.6.140.0170.00316.18
5.6.130.0150.00916.18
5.6.120.0110.01116.18
5.6.110.0270.00316.18
5.6.100.0220.00616.18
5.6.90.0250.00516.18
5.6.80.0150.01516.18
5.6.70.0360.00516.18
5.6.60.0260.00616.18
5.6.50.0210.00716.18
5.6.40.0230.00716.18
5.6.30.0200.00916.18
5.6.20.0180.01116.18
5.6.10.0180.01116.18
5.6.00.0200.00916.18
5.5.380.0210.00716.18
5.5.370.0290.00016.18
5.5.360.0150.01116.18
5.5.350.0270.00016.18
5.5.340.0140.01116.18
5.5.330.0270.00016.18
5.5.320.0220.00316.18
5.5.310.0330.00316.18
5.5.300.0270.00016.18
5.5.290.0250.00016.18
5.5.280.0250.00316.18
5.5.270.0210.00716.18
5.5.260.0220.00316.18
5.5.250.0240.00016.18
5.5.240.0250.00916.18
5.5.230.0210.00616.18
5.5.220.0240.00016.18
5.5.210.0130.01616.18
5.5.200.0290.00016.18
5.5.190.0230.00316.18
5.5.180.0260.00316.18
5.5.170.0260.00316.18
5.5.160.0210.00716.18
5.5.150.0230.00616.18
5.5.140.0160.01216.18
5.5.130.0230.00616.18
5.5.120.0250.00316.18
5.5.110.0220.00416.18
5.5.100.0210.00316.18
5.5.90.0200.00916.18
5.5.80.0200.00816.18
5.5.70.0260.00916.18
5.5.60.0240.00316.18
5.5.50.0240.00016.18
5.5.40.0220.00816.18
5.5.30.0240.00316.18
5.5.20.0290.00416.18
5.5.10.0220.00716.18
5.5.00.0230.00316.18
5.4.450.0090.00916.18
5.4.440.0160.00416.18
5.4.430.0190.00016.18
5.4.420.0110.00816.18
5.4.410.0190.00316.18
5.4.400.0150.00716.18
5.4.390.0220.00016.18
5.4.380.0110.00816.18
5.4.370.0150.00416.18
5.4.360.0180.00316.18
5.4.350.0150.00816.18
5.4.340.0150.00816.18
5.4.330.0130.00616.18
5.4.320.0190.00416.18
5.4.310.0210.00316.18
5.4.300.0200.00316.18
5.4.290.0200.00316.18
5.4.280.0170.00616.18
5.4.270.0220.00016.18
5.4.260.0180.00516.18
5.4.250.0160.00316.18
5.4.240.0060.00616.18
5.4.230.0120.01216.18
5.4.220.0130.00716.18
5.4.210.0060.00616.18
5.4.200.0100.00016.18
5.4.190.0100.00016.18
5.4.180.0070.00316.18
5.4.170.0110.00016.18
5.4.160.0110.00016.18
5.4.150.0070.00416.18
5.4.140.0050.00516.18
5.4.130.0070.00316.18
5.4.120.0080.00316.18
5.4.110.0070.00416.18
5.4.100.0050.00516.18
5.4.90.0100.00016.18
5.4.80.0080.00316.18
5.4.70.0110.00016.18
5.4.60.0190.00016.18
5.4.50.0090.00916.18
5.4.40.0110.00716.18
5.4.30.0190.00016.18
5.4.20.0150.00416.18
5.4.10.0130.00616.18
5.4.00.0120.00616.18
5.3.290.0180.00316.18
5.3.280.0160.00316.18
5.3.270.0080.01116.18
5.3.260.0120.00916.18
5.3.250.0110.00716.18
5.3.240.0080.01116.18
5.3.230.0180.00616.18
5.3.220.0040.01516.18
5.3.210.0130.01016.18
5.3.200.0200.00316.18
5.3.190.0170.00716.18
5.3.180.0170.00716.18
5.3.170.0140.00916.18
5.3.160.0130.00716.18
5.3.150.0180.00416.18
5.3.140.0190.00016.18
5.3.130.0040.00716.18
5.3.120.0150.00816.18
5.3.110.0050.00516.18
5.3.100.0100.00016.18
5.3.90.0210.00416.18
5.3.80.0190.00316.18
5.3.70.0050.00516.18
5.3.60.0120.00816.18
5.3.50.0080.00416.18
5.3.40.0090.00916.18
5.3.30.0140.00616.18
5.3.20.0070.01516.18
5.3.10.0150.00316.18
5.3.00.0120.00916.18
5.2.170.0140.00316.18
5.2.160.0130.00316.18
5.2.150.0080.00816.18
5.2.140.0090.00916.18
5.2.130.0120.00416.18
5.2.120.0150.00016.18
5.2.110.0140.00516.18
5.2.100.0150.00316.18
5.2.90.0090.00916.18
5.2.80.0090.00016.18
5.2.70.0060.00316.18
5.2.60.0110.00016.18
5.2.50.0040.00416.18
5.2.40.0120.00016.18
5.2.30.0150.00016.18
5.2.20.0070.00716.18
5.2.10.0070.00716.18
5.2.00.0140.00316.18
5.1.60.0090.00616.18
5.1.50.0120.00416.18
5.1.40.0160.00016.18
5.1.30.0040.00416.18
5.1.20.0110.00616.18
5.1.10.0080.00016.18
5.1.00.0070.00016.18
5.0.50.0140.00016.18
5.0.40.0080.00016.18
5.0.30.0070.00716.18
5.0.20.0070.00016.18
5.0.10.0110.00316.18
5.0.00.0130.00016.18
4.4.90.0000.00816.18
4.4.80.0000.00416.18
4.4.70.0080.00016.18
4.4.60.0040.00016.18
4.4.50.0070.00016.18
4.4.40.0020.00416.18
4.4.30.0000.00816.18
4.4.20.0070.00016.18
4.4.10.0070.00016.18
4.4.00.0070.00016.18
4.3.110.0070.00016.18
4.3.100.0060.00016.18
4.3.90.0000.00716.18
4.3.80.0000.00816.18
4.3.70.0080.00016.18
4.3.60.0070.00016.18
4.3.50.0060.00016.18
4.3.40.0070.00016.18
4.3.30.0050.00016.18
4.3.20.0070.00016.18
4.3.10.0060.00016.18
4.3.00.0050.00016.18

preferences:
30.08 ms | 403 KiB | 5 Q