3v4l.org

run code in 300+ PHP versions simultaneously
<?php $input = [ ["relation" => "OR"], ["color" => 'green'], ["color" => 'yellow'], ["relation" => "AND"], ["color" => 'black'], ["color" => 'orange'], ["relation" => "OR"], ["color" => 'blue'], ["color" => 'violet'], ]; $ref = []; $result = &$ref; foreach ($input as $row) { if (key($row) === 'relation') { if ($ref) { // not the first relation encountered $ref = &$ref[]; // set $ref to point to new deeper subarray } $ref = $row; // push relation } else { $ref[] = $row; // push color into reference } } var_export($result);

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.5.00.0150.00619.90
8.4.150.0020.00014.05
8.4.140.0120.00517.52
8.4.130.0130.00717.84
8.4.120.0030.00720.46
8.4.110.0030.00622.28
8.4.100.0140.00717.77
8.4.90.0060.00422.43
8.4.80.0060.00220.84
8.4.70.0050.00319.04
8.4.60.0090.01220.66
8.4.50.0100.00917.71
8.4.40.0070.01024.10
8.4.30.0040.00420.83
8.4.20.0190.00020.63
8.4.10.0060.00323.94
8.3.280.0130.00818.40
8.3.270.0120.00716.50
8.3.260.0030.00616.60
8.3.250.0150.00420.78
8.3.240.0130.00616.76
8.3.230.0090.00816.63
8.3.220.0110.00620.76
8.3.210.0100.00616.66
8.3.200.0100.00716.81
8.3.190.0100.00917.39
8.3.180.0090.00916.53
8.3.170.0140.00419.19
8.3.160.0060.00316.82
8.3.150.0120.00617.17
8.3.140.0000.01418.94
8.3.130.0070.00318.40
8.3.120.0040.00420.69
8.3.110.0040.00420.94
8.3.100.0060.00324.06
8.3.90.0040.01126.77
8.3.80.0080.00017.97
8.3.70.0120.00318.55
8.3.60.0120.00316.88
8.3.50.0110.01116.54
8.3.40.0100.00321.90
8.3.30.0070.00718.85
8.3.20.0040.00424.18
8.3.10.0000.00824.66
8.3.00.0040.00426.16
8.2.290.0080.00816.73
8.2.280.0060.00818.30
8.2.270.0070.01317.29
8.2.260.0120.00620.44
8.2.250.0080.00322.57
8.2.240.0040.00417.09
8.2.230.0030.00622.58
8.2.220.0070.00437.54
8.2.210.0070.00726.77
8.2.200.0000.00816.63
8.2.190.0180.00016.72
8.2.180.0130.00616.75
8.2.170.0070.00719.09
8.2.160.0150.00022.96
8.2.150.0040.00425.66
8.2.140.0030.00524.66
8.2.130.0040.00426.16
8.2.120.0000.00826.16
8.2.110.0000.01117.80
8.2.100.0100.00317.48
8.2.90.0050.00317.50
8.2.80.0000.00818.64
8.2.70.0040.00417.50
8.2.60.0040.00417.48
8.2.50.0080.00018.05
8.2.40.0040.00419.36
8.2.30.0060.01017.75
8.2.20.0090.00717.63
8.2.10.0110.00717.59
8.2.00.0150.00017.59
8.1.330.0100.00922.07
8.1.320.0030.00616.10
8.1.310.0030.00616.72
8.1.300.0030.00620.30
8.1.290.0060.00330.84
8.1.280.0060.01125.92
8.1.270.0040.01523.85
8.1.260.0040.00426.35
8.1.250.0080.00028.09
8.1.240.0060.00323.96
8.1.230.0100.00320.99
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0080.00017.52
8.1.190.0050.00317.00
8.1.180.0000.00818.10
8.1.170.0000.00817.62
8.1.160.0040.01217.59
8.1.150.0160.00017.59
8.1.140.0130.00317.59
8.1.130.0120.00417.59
8.1.120.0050.01117.59
8.1.110.0130.00217.59
8.1.100.0130.00317.59
8.1.90.0130.00317.59
8.1.80.0140.00217.59
8.1.70.0100.00717.59
8.1.60.0150.00417.59
8.1.50.0160.00317.59
8.1.40.0200.00017.59
8.1.30.0110.00617.59
8.1.20.0130.00417.59
8.1.10.0140.00517.59
8.1.00.0090.00917.59
8.0.300.0040.00418.77
8.0.290.0040.00416.75
8.0.280.0160.00017.59
8.0.270.0120.00417.59
8.0.260.0150.00017.59
8.0.250.0140.00317.59
8.0.240.0120.00317.59
8.0.230.0080.00817.59
8.0.220.0110.00717.59
8.0.210.0090.00917.59
8.0.200.0120.00417.59
8.0.190.0130.00317.59
8.0.180.0030.01317.59
8.0.170.0090.00917.59
8.0.160.0170.00017.59
8.0.150.0130.00317.59
8.0.140.0160.00017.59
8.0.130.0120.00417.59
8.0.120.0080.00817.59
8.0.110.0070.00717.59
8.0.100.0110.00417.59
8.0.90.0090.00617.59
8.0.80.0140.00217.59
8.0.70.0120.00417.59
8.0.60.0120.00317.59
8.0.50.0170.00017.59
8.0.30.0160.00017.59
8.0.20.0110.00417.59
8.0.10.0110.00417.59

preferences:
31.8 ms | 403 KiB | 5 Q