3v4l.org

run code in 300+ PHP versions simultaneously
<?php $json = '{"array":[{"Name": "John Doe", "mail": "john-doe@gmail.com"}, {"Name": "Alex Smith", "mail": "alex-smith@gmx.com"}]}'; $target = json_decode($json, true); $insert = array("Name"=>"Thomas Dover", "mail"=>"thomas-dover@icloud.com"); // We will overwrite $val later so we want a reference foreach($target as $x => &$val) { // Temporary array $between = []; // Flag for if/when we find the first person $foundStart = false; foreach($val as $key => $v) { // If we found the first person previously, and this is our second person if($foundStart && 'Alex Smith' === $v['Name']) { // Insert $between[] = $insert; // Reset the flag just in case the second person is found again $foundStart = false; }elseif('John Doe' === $v['Name']){ // Flag that we found the first person $foundStart = true; } // No matter what, append our current item to the temp array $between[] = $v; } // Overwrite our original loop's variable with our temporary $val = $between; } // Clean up reference variable so surprises don't happen unset($val); echo json_encode($target);

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.0130.00618.64
8.4.120.0090.01124.29
8.4.110.0090.01018.95
8.4.100.0150.00517.78
8.4.90.0130.00720.65
8.4.80.0070.00618.96
8.4.70.0140.00518.98
8.4.60.0080.01318.79
8.4.50.0120.00722.46
8.4.40.0130.00617.56
8.4.30.0040.00418.61
8.4.20.0070.01117.81
8.4.10.0170.00722.07
8.3.260.0090.00816.66
8.3.250.0080.01018.89
8.3.240.0110.00817.08
8.3.230.0110.00216.75
8.3.220.0060.00219.08
8.3.210.0080.01216.61
8.3.200.0050.00416.66
8.3.190.0070.00217.10
8.3.180.0140.00418.80
8.3.170.0160.00318.41
8.3.160.0070.01019.05
8.3.150.0090.00917.32
8.3.140.0050.00320.71
8.3.130.0180.00018.55
8.3.120.0060.00320.73
8.3.110.0030.00720.94
8.3.100.0030.01016.61
8.3.90.0040.00426.77
8.3.80.0040.00416.60
8.3.70.0190.00416.73
8.3.60.0040.01116.50
8.3.50.0160.00618.15
8.3.40.0070.01020.34
8.3.30.0110.00418.67
8.3.20.0040.00424.18
8.3.10.0000.00824.66
8.3.00.0030.00526.16
8.2.290.0120.00816.44
8.2.280.0140.00520.38
8.2.270.0090.00918.94
8.2.260.0090.00916.91
8.2.250.0000.00816.68
8.2.240.0040.00417.55
8.2.230.0030.00622.58
8.2.220.0060.01324.06
8.2.210.0040.00426.77
8.2.200.0040.00416.88
8.2.190.0120.00316.63
8.2.180.0120.00425.92
8.2.170.0150.00618.70
8.2.160.0100.00322.96
8.2.150.0040.00425.66
8.2.140.0080.00024.66
8.2.130.0080.00026.16
8.2.120.0070.00026.16
8.2.110.0030.00622.20
8.2.100.0040.00817.78
8.2.90.0070.00019.47
8.2.80.0040.00418.75
8.2.70.0060.00317.75
8.2.60.0080.00017.93
8.2.50.0000.00818.07
8.2.40.0030.00618.15
8.2.30.0040.00418.05
8.2.20.0000.00719.25
8.2.10.0000.00818.00
8.2.00.0050.00219.31
8.1.330.0110.00721.83
8.1.320.0060.00716.16
8.1.310.0100.00016.47
8.1.300.0040.00418.18
8.1.290.0060.00330.84
8.1.280.0100.00725.92
8.1.270.0040.00423.86
8.1.260.0040.00426.35
8.1.250.0070.00028.09
8.1.240.0090.00020.41
8.1.230.0070.00317.83
8.1.220.0000.00917.76
8.1.210.0000.00918.77
8.1.200.0060.00317.48
8.1.190.0030.00617.23
8.1.180.0030.00518.10
8.1.170.0030.00618.50
8.1.160.0030.00319.06
8.1.150.0070.00018.52
8.1.140.0050.00317.52
8.1.130.0040.00419.03
8.1.120.0070.00017.44
8.1.110.0040.00417.45
8.1.100.0000.00717.36
8.1.90.0080.00317.39
8.1.80.0150.00117.39
8.1.70.0080.00817.43
8.1.60.0130.00517.53
8.1.50.0130.00417.53
8.1.40.0140.00417.54
8.1.30.0120.00617.61
8.1.20.0140.00417.65
8.1.10.0140.00417.52
8.1.00.0100.00817.51
8.0.300.0040.00418.77
8.0.290.0000.00716.58
8.0.280.0030.00318.37
8.0.270.0000.00816.74
8.0.260.0000.00618.45
8.0.250.0070.00016.96
8.0.240.0000.00716.90
8.0.230.0000.00816.95
8.0.220.0060.00816.82
8.0.210.0040.01116.86
8.0.200.0110.00416.92
8.0.190.0080.00616.91
8.0.180.0120.00316.86
8.0.170.0100.00416.86
8.0.160.0080.00616.85
8.0.150.0060.00916.82
8.0.140.0110.00516.80
8.0.130.0100.00616.87
8.0.120.0090.00616.86
8.0.110.0150.00116.86
8.0.100.0110.00416.88
8.0.90.0100.00316.79
8.0.80.0090.00516.74
8.0.70.0060.00616.73
8.0.60.0150.00016.87
8.0.50.0110.00316.85
8.0.30.0120.00416.78
8.0.20.0070.00516.87
8.0.10.0080.00517.01
7.4.330.0060.00015.55
7.4.320.0000.00616.59
7.4.300.0100.00316.59
7.4.290.0120.00316.59
7.4.280.0120.00416.57
7.4.270.0150.00316.49
7.4.260.0120.00316.54
7.4.250.0100.00316.52
7.4.240.0070.00716.61
7.4.230.0140.00316.54
7.4.220.0050.00716.50
7.4.210.0110.00316.58
7.4.200.0080.00416.46
7.4.190.0070.00316.59
7.4.180.0110.00416.55
7.4.160.0040.00616.36
7.4.150.0060.00616.35
7.4.140.0050.00716.43
7.4.130.0110.00316.42
7.4.120.0080.00316.37
7.4.110.0070.00416.28
7.4.100.0090.00316.50
7.4.90.0050.00516.46
7.4.80.0080.00316.44
7.4.70.0090.00516.48
7.4.60.0090.00616.46
7.4.50.0120.00216.32
7.4.40.0140.00216.32
7.4.30.0080.00616.47
7.4.20.0110.00416.46
7.4.10.0090.00416.49
7.4.00.0100.00416.44

preferences:
34.58 ms | 403 KiB | 5 Q