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"); // Temporary array $between = []; // Flag for if/when we find the first person $foundStart = false; foreach($target['array'] 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 $target['array'] = $between; 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.00617.62
8.4.120.0110.00924.40
8.4.110.0060.00423.28
8.4.100.0120.00718.67
8.4.90.0100.00818.97
8.4.80.0090.01118.84
8.4.70.0090.00617.86
8.4.60.0120.00919.00
8.4.50.0100.01019.02
8.4.40.0200.00017.68
8.4.30.0100.01018.88
8.4.20.0110.00417.86
8.4.10.0030.00622.36
8.3.260.0110.00817.17
8.3.250.0130.00618.83
8.3.240.0120.00717.18
8.3.230.0090.00916.58
8.3.220.0100.00818.82
8.3.210.0040.00416.79
8.3.200.0040.00516.63
8.3.190.0090.01016.95
8.3.180.0120.00717.23
8.3.170.0060.01222.26
8.3.160.0150.00317.30
8.3.150.0160.00317.14
8.3.140.0040.00416.57
8.3.130.0000.01116.45
8.3.120.0060.00318.93
8.3.110.0060.01320.94
8.3.100.0030.00616.53
8.3.90.0050.00316.70
8.3.80.0060.00316.50
8.3.70.0070.01416.58
8.3.60.0040.01116.75
8.3.50.0070.01020.00
8.3.40.0100.00320.07
8.3.30.0070.00718.84
8.3.20.0040.00424.18
8.3.10.0080.00024.66
8.3.00.0000.00726.16
8.2.290.0120.00820.50
8.2.280.0120.00718.47
8.2.270.0120.00616.47
8.2.260.0070.01118.66
8.2.250.0050.00318.50
8.2.240.0030.00618.85
8.2.230.0110.00722.58
8.2.220.0040.00724.06
8.2.210.0120.00326.77
8.2.200.0090.00018.17
8.2.190.0070.00716.58
8.2.180.0070.00725.92
8.2.170.0000.01619.04
8.2.160.0090.00622.96
8.2.150.0020.00525.66
8.2.140.0080.00024.66
8.2.130.0040.00426.16
8.2.120.0050.00320.96
8.2.110.0040.00420.52
8.2.100.0090.00317.72
8.2.90.0030.00717.88
8.2.80.0090.00018.86
8.2.70.0000.00817.38
8.2.60.0030.00617.63
8.2.50.0000.00818.05
8.2.40.0000.00818.16
8.2.30.0000.00718.11
8.2.20.0000.00719.25
8.2.10.0000.00718.23
8.2.00.0000.00719.23
8.1.330.0110.00821.78
8.1.320.0140.00716.03
8.1.310.0080.00016.69
8.1.300.0000.01116.05
8.1.290.0030.00618.88
8.1.280.0070.00725.92
8.1.270.0170.00024.66
8.1.260.0090.00626.35
8.1.250.0000.00728.09
8.1.240.0000.00922.01
8.1.230.0080.00417.82
8.1.220.0040.00417.74
8.1.210.0040.00418.77
8.1.200.0030.00617.48
8.1.190.0040.00417.35
8.1.180.0040.00418.10
8.1.170.0030.00617.62
8.1.160.0030.00318.93
8.1.150.0000.00718.69
8.1.140.0000.00817.36
8.1.130.0030.00319.00
8.1.120.0040.00417.45
8.1.110.0070.00017.34
8.1.100.0000.00717.50
8.1.90.0120.00417.50
8.1.80.0130.00217.44
8.1.70.0100.00517.43
8.1.60.0150.00317.59
8.1.50.0080.00917.48
8.1.40.0130.00517.53
8.1.30.0090.00617.59
8.1.20.0080.00417.67
8.1.10.0000.01217.45
8.1.00.0100.00317.48
8.0.300.0080.00018.77
8.0.290.0000.00816.75
8.0.280.0000.00718.37
8.0.270.0000.00716.73
8.0.260.0040.00418.36
8.0.250.0000.00716.98
8.0.240.0050.00316.96
8.0.230.0040.00416.87
8.0.220.0050.00516.76
8.0.210.0070.00316.76
8.0.200.0080.00516.97
8.0.190.0120.00216.79
8.0.180.0130.00316.90
8.0.170.0080.00916.75
8.0.160.0130.00316.96
8.0.150.0050.01016.70
8.0.140.0130.00316.81
8.0.130.0150.00016.80
8.0.120.0150.00016.87
8.0.110.0070.00716.80
8.0.100.0050.01016.86
8.0.90.0090.00616.91
8.0.80.0120.00316.93
8.0.70.0150.00016.90
8.0.60.0060.00916.66
8.0.50.0110.00516.86
8.0.30.0110.00416.84
8.0.20.0150.00016.90
8.0.10.0110.00316.97
7.4.330.0020.00515.55
7.4.320.0030.00316.60
7.4.300.0040.00916.58
7.4.290.0150.00316.48
7.4.280.0090.00916.50
7.4.270.0150.00316.52
7.4.260.0120.00416.62
7.4.250.0100.00316.46
7.4.240.0070.00716.60
7.4.230.0130.00316.50
7.4.220.0060.00616.57
7.4.210.0110.00216.59
7.4.200.0110.00016.47
7.4.190.0050.00516.59
7.4.180.0070.00716.42
7.4.160.0120.00016.42
7.4.150.0080.00716.49
7.4.140.0000.01116.34
7.4.130.0120.00316.54
7.4.120.0100.00016.46
7.4.110.0090.00516.47
7.4.100.0080.00016.50
7.4.90.0060.00016.52
7.4.80.0020.00516.31
7.4.70.0070.00316.48
7.4.60.0030.00616.36
7.4.50.0040.00816.41
7.4.40.0040.00416.38
7.4.30.0100.00016.42
7.4.20.0050.00516.50
7.4.10.0050.00516.45
7.4.00.0050.00516.43

preferences:
30.86 ms | 403 KiB | 5 Q