3v4l.org

run code in 300+ PHP versions simultaneously
<?php function insertNewNodeTest() { $array = array( 'a' => array( 'a_1' => 'a_1 text', ), ); $object = json_decode( json_encode( $array )); //** $object = new ArrayObject( $array, 0, "RecursiveArrayIterator" ); $iterator = new RecursiveIteratorIterator( new RecursiveArrayIterator( $object ), RecursiveIteratorIterator::CHILD_FIRST ); //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// foreach( $iterator as $key => $current ) { // insert a new empty node if( $key == 'a_1' ) { $iterator->getInnerIterator()->offsetSet( 'a_2', new stdClass() ); } // add new leaf into the previously inserted node if( $key == 'a_2' ) { $current->ex_empty = 'not empty now'; } // add another leaf into the previously inserted node if( $key == 'a_2' ) { $current->second_leaf = 'leaf with property'; } // add third leaf WITH ITERATOR(!) instead of using the $current->third_leaf if( $key == 'a_2' && $iterator->getInnerIterator()->hasChildren() ) { $iterator->getInnerIterator()->getChildren()->offsetSet( 'third_leaf', 'leaf with iterator'); } } print_r($object); } insertNewNodeTest();

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.0060.01016.25
8.3.50.0120.00722.10
8.3.40.0180.00318.66
8.3.30.0100.00319.09
8.3.20.0040.00420.13
8.3.10.0000.00723.71
8.3.00.0080.00020.95
8.2.180.0140.00016.38
8.2.170.0140.00022.96
8.2.160.0070.00720.40
8.2.150.0050.00324.18
8.2.140.0060.00324.66
8.2.130.0100.00726.16
8.2.120.0040.00419.82
8.2.110.0040.00422.22
8.2.100.0090.00317.72
8.2.90.0030.00619.05
8.2.80.0060.00318.04
8.2.70.0000.00917.63
8.2.60.0000.00917.80
8.2.50.0030.00718.07
8.2.40.0000.00818.16
8.2.30.0080.00018.14
8.2.20.0050.00317.60
8.2.10.0040.00417.76
8.2.00.0000.00717.68
8.1.280.0090.00625.92
8.1.270.0000.00823.88
8.1.260.0040.00426.35
8.1.250.0040.00428.09
8.1.240.0060.00323.71
8.1.230.0070.00319.21
8.1.220.0040.00417.74
8.1.210.0030.00518.77
8.1.200.0070.00717.25
8.1.190.0040.00417.41
8.1.180.0030.00518.10
8.1.170.0060.00318.70
8.1.160.0030.00521.95
8.1.150.0020.00518.65
8.1.140.0000.00717.46
8.1.130.0030.00317.76
8.1.120.0040.00417.48
8.1.110.0060.00317.45
8.1.100.0070.00017.50
8.1.90.0040.00417.41
8.1.80.0040.00417.39
8.1.70.0000.00717.33
8.1.60.0030.00617.49
8.1.50.0040.00417.52
8.1.40.0050.00317.54
8.1.30.0040.00417.51
8.1.20.0080.00017.56
8.1.10.0000.00717.49
8.1.00.0040.00417.49
8.0.300.0040.00418.77
8.0.290.0050.00217.18
8.0.280.0000.00718.42
8.0.270.0020.00517.27
8.0.260.0030.00316.85
8.0.250.0070.00016.89
8.0.240.0060.00316.97
8.0.230.0070.00017.02
8.0.220.0040.00416.87
8.0.210.0000.00716.91
8.0.200.0040.00417.04
8.0.190.0000.00816.86
8.0.180.0030.00517.00
8.0.170.0020.00516.93
8.0.160.0000.00816.90
8.0.150.0040.00416.88
8.0.140.0040.00416.86
8.0.130.0000.00813.38
8.0.120.0000.00816.83
8.0.110.0050.00316.87
8.0.100.0000.00716.93
8.0.90.0030.00516.74
8.0.80.0060.00916.86
8.0.70.0000.00716.98
8.0.60.0050.00216.91
8.0.50.0050.00316.95
8.0.30.0070.01217.14
8.0.20.0110.00717.40
8.0.10.0040.00416.90
8.0.00.0110.01016.79
7.4.330.0000.00515.15
7.4.320.0030.00316.54
7.4.300.0000.00616.48
7.4.290.0020.00516.41
7.4.280.0080.00016.50
7.4.270.0000.00716.61
7.4.260.0000.00716.63
7.4.250.0000.00816.56
7.4.240.0030.00416.58
7.4.230.0030.00316.65
7.4.220.0030.01316.64
7.4.210.0110.00516.48
7.4.200.0030.00316.66
7.4.190.0040.00416.43
7.4.160.0120.00416.52
7.4.150.0070.01017.40
7.4.140.0050.01217.86
7.4.130.0110.00616.48
7.4.120.0100.00816.61
7.4.110.0090.01216.69
7.4.100.0130.00716.64
7.4.90.0180.00316.49
7.4.80.0090.01219.39
7.4.70.0150.00316.49
7.4.60.0120.00916.39
7.4.50.0060.00316.42
7.4.40.0000.01522.77
7.4.30.0130.00316.65
7.4.10.0100.01016.55
7.4.00.0070.00815.63
7.3.330.0030.00313.31
7.3.320.0000.00613.27
7.3.310.0040.00416.41
7.3.300.0000.00716.18
7.3.290.0070.00016.40
7.3.280.0120.00416.28
7.3.270.0030.01417.40
7.3.260.0070.01016.42
7.3.250.0120.00716.47
7.3.240.0070.01016.59
7.3.230.0080.01116.45
7.3.210.0060.01516.41
7.3.200.0030.01419.39
7.3.190.0180.00616.64
7.3.180.0110.01016.44
7.3.170.0140.00616.58
7.3.160.0100.00716.43
7.3.130.0090.00916.25
7.3.120.0080.00915.68
7.3.110.0070.01016.54
7.3.100.0090.00916.57
7.3.90.0040.01516.28
7.3.80.0050.00516.38
7.3.70.0110.00416.19
7.3.60.0070.00716.33
7.3.50.0090.00616.15
7.3.40.0060.00316.44
7.3.30.0000.01416.47
7.3.20.0040.01118.20
7.3.10.0060.00918.09
7.3.00.0070.00718.37
7.2.330.0140.00516.71
7.2.320.0060.00916.78
7.2.310.0160.00916.85
7.2.300.0090.00616.65
7.2.290.0130.00316.79
7.2.260.0100.01016.62
7.2.250.0110.01116.81
7.2.240.0150.00016.66
7.2.230.0030.01016.75
7.2.220.0130.00716.83
7.2.210.0040.00816.75
7.2.200.0070.01016.59
7.2.190.0030.01216.56
7.2.180.0100.00616.58
7.2.170.0060.00916.42
7.2.160.0070.01016.46
7.2.150.0030.01418.38
7.2.140.0070.00718.46
7.2.130.0030.00718.56
7.2.120.0130.00018.33
7.2.110.0000.01618.61
7.2.100.0080.00418.43
7.2.90.0070.00318.46
7.2.80.0120.00318.42
7.2.70.0100.00618.41
7.2.60.0080.00817.70
7.2.50.0070.00718.53
7.2.40.0030.01318.40
7.2.30.0080.00418.62
7.2.20.0090.00618.32
7.2.10.0000.01118.55
7.2.00.0030.01018.55
7.1.330.0030.00917.45
7.1.320.0070.01017.39
7.1.310.0030.00717.36
7.1.300.0110.00317.23
7.1.290.0060.00317.24
7.1.280.0030.01017.27
7.1.270.0090.00617.55
7.1.260.0100.00317.32
7.1.250.0000.01017.33
7.1.240.0040.01217.37
7.1.230.0070.00317.28
7.1.220.0040.00417.34
7.1.210.0070.00717.24
7.1.200.0020.01216.50
7.1.190.0060.00617.43
7.1.180.0000.01317.26
7.1.170.0090.00317.43
7.1.160.0100.00317.38
7.1.150.0040.01117.42
7.1.140.0030.00717.29
7.1.130.0070.01017.54
7.1.120.0070.01017.28
7.1.110.0060.00317.39
7.1.100.0030.01317.25
7.1.90.0060.00917.27
7.1.80.0060.00917.27
7.1.70.0050.00817.15
7.1.60.0110.01018.30
7.1.50.0040.01217.23
7.1.40.0030.00717.29
7.1.30.0090.00617.38
7.1.20.0030.01217.50
7.1.10.0090.00317.46
7.1.00.0090.03819.87
7.0.330.0070.00717.21
7.0.320.0000.01117.11
7.0.310.0040.01116.92
7.0.300.0160.00017.18
7.0.290.0110.00417.00
7.0.280.0090.00617.00
7.0.270.0070.00717.25
7.0.260.0000.01217.04
7.0.250.0030.01017.13
7.0.240.0060.00917.09
7.0.230.0080.00816.94
7.0.220.0150.00016.97
7.0.210.0060.00316.84
7.0.200.0090.00216.81
7.0.190.0080.00817.17
7.0.180.0060.00316.91
7.0.170.0100.00317.05
7.0.160.0060.00617.05
7.0.150.0040.01117.08
7.0.140.0090.03719.54
7.0.130.0090.00017.09
7.0.120.0060.00616.93
7.0.110.0030.01017.04
7.0.100.0030.01016.96
7.0.90.0200.03818.43
7.0.80.0220.03018.60
7.0.70.0180.02518.41
7.0.60.0270.02318.46
7.0.50.0360.03818.52
7.0.40.0070.04517.46
7.0.30.0070.04617.61
7.0.20.0070.02717.55
7.0.10.0070.04317.51
7.0.00.0110.04017.58
5.6.400.0060.00916.15
5.6.390.0070.00316.03
5.6.380.0100.00715.93
5.6.370.0060.01016.23
5.6.360.0030.01315.61
5.6.350.0040.01116.07
5.6.340.0090.00616.25
5.6.330.0030.01316.00
5.6.320.0040.01115.96
5.6.310.0090.00616.05
5.6.300.0000.01516.04
5.6.290.0090.00616.03
5.6.280.0070.00716.03
5.6.270.0070.01116.03
5.6.260.0090.00915.82
5.6.250.0110.00816.07
5.6.240.0070.01115.92
5.6.230.0110.01918.24
5.6.220.0050.04018.44
5.6.210.0020.02718.19
5.6.200.0070.04818.45
5.6.190.0050.04518.55
5.6.180.0030.03018.51
5.6.170.0130.03518.51
5.6.160.0050.05118.53
5.6.150.0080.04318.38
5.6.140.0100.04518.44
5.6.130.0070.04318.47
5.6.120.0070.04018.42
5.6.110.0070.02918.47
5.6.100.0060.03018.61
5.6.90.0120.04518.51
5.6.80.0110.04118.12
5.6.70.0080.04018.18
5.6.60.0130.03318.09
5.6.50.0070.04518.15
5.6.40.0070.04118.16
5.6.30.0060.04518.29
5.6.20.0110.04218.25
5.6.10.0100.04218.15
5.6.00.0040.04418.22
5.5.380.0080.01115.93
5.5.370.0030.03918.22
5.5.360.0020.02718.25
5.5.350.0020.02718.18
5.5.340.0080.04518.43
5.5.330.0060.03218.38
5.5.320.0110.02718.39
5.5.310.0030.03418.35
5.5.300.0070.03518.36
5.5.290.0080.04118.30
5.5.280.0080.04218.33
5.5.270.0100.02718.51
5.5.260.0090.04218.33
5.5.250.0080.04518.25
5.5.240.0070.04317.96
5.5.230.0100.04117.89
5.5.220.0100.04118.10
5.5.210.0050.04418.06
5.5.200.0080.03218.01
5.5.190.0060.04617.96
5.5.180.0080.04417.95
5.5.170.0110.00015.86
5.5.160.0070.03118.05
5.5.150.0100.04018.06
5.5.140.0030.04317.97
5.5.130.0050.04218.11
5.5.120.0120.03718.02
5.5.110.0060.04618.13
5.5.100.0070.04517.99
5.5.90.0110.03618.02
5.5.80.0070.04417.87
5.5.70.0070.04417.98
5.5.60.0050.04317.88
5.5.50.0070.02517.76
5.5.40.0060.03018.05
5.5.30.0070.04617.90
5.5.20.0130.02617.83
5.5.10.0070.04218.00
5.5.00.0070.04517.86
5.4.450.0040.04416.06
5.4.440.0030.03816.15
5.4.430.0040.04116.11
5.4.420.0100.03816.05
5.4.410.0050.04216.12
5.4.400.0070.03815.88
5.4.390.0080.04015.95
5.4.380.0050.03815.89
5.4.370.0050.04415.77
5.4.360.0080.03915.86
5.4.350.0120.03615.93
5.4.340.0130.02415.90
5.4.330.0040.00412.63
5.4.320.0030.04116.02
5.4.310.0060.04015.99
5.4.300.0120.02715.98
5.4.290.0020.03115.73
5.4.280.0050.04415.73
5.4.270.0060.02515.89
5.4.260.0100.03316.04
5.4.250.0050.04115.81
5.4.240.0030.04215.85
5.4.230.0030.04415.80
5.4.220.0070.04515.83
5.4.210.0070.03515.84
5.4.200.0050.04015.87
5.4.190.0070.04115.88
5.4.180.0030.04415.76
5.4.170.0100.03715.90
5.4.160.0050.04015.90
5.4.150.0010.04815.78
5.4.140.0090.03314.61
5.4.130.0030.02414.65
5.4.120.0060.02514.52
5.4.110.0100.03514.65
5.4.100.0050.03814.58
5.4.90.0050.03714.58
5.4.80.0110.02714.51
5.4.70.0050.02214.55
5.4.60.0090.03214.56
5.4.50.0080.03314.44
5.4.40.0090.03614.57
5.4.30.0070.03914.55
5.4.20.0080.01814.45
5.4.10.0050.04214.53
5.4.00.0130.02114.28
5.3.290.0050.03513.94
5.3.280.0050.03513.87
5.3.270.0050.04413.88
5.3.260.0050.04413.89
5.3.250.0030.04513.90
5.3.240.0100.03713.81
5.3.230.0060.04013.83
5.3.220.0000.03113.85
5.3.210.0090.04113.65
5.3.200.0120.03513.73
5.3.190.0050.04413.76
5.3.180.0080.03013.85
5.3.170.0100.02013.90
5.3.160.0030.02613.76
5.3.150.0080.04013.82
5.3.140.0050.04413.86
5.3.130.0060.03813.87
5.3.120.0050.03913.85
5.3.110.0020.04513.87
5.3.100.0080.04013.63
5.3.90.0070.03713.62
5.3.80.0050.03513.47
5.3.70.0070.03713.58
5.3.60.0030.03713.48
5.3.50.0050.03213.49
5.3.40.0020.04413.47
5.3.30.0030.04213.52
5.3.20.0050.03913.31
5.3.10.0030.04113.27
5.3.00.0040.04013.25
5.2.170.0030.04311.19
5.2.160.0100.05311.25
5.2.150.0030.03311.25
5.2.140.0100.05311.19
5.2.130.0100.03711.16
5.2.120.0030.06011.25
5.2.110.0030.04311.22
5.2.100.0030.04010.97
5.2.90.0070.06011.17
5.2.80.0100.06011.17
5.2.70.0170.04311.16
5.2.60.0030.06310.97
5.2.50.0130.03710.95
5.2.40.0070.06011.07
5.2.30.0100.05010.99
5.2.20.0100.05310.83
5.2.10.0070.05310.74
5.2.00.0000.06710.66
5.1.60.0070.03710.00
5.1.50.0030.0539.84
5.1.40.0000.05710.08
5.1.30.0030.05310.30
5.1.20.0000.06010.27
5.1.10.0030.04310.20
5.1.00.0030.04710.16
5.0.50.0070.0478.58
5.0.40.0000.0438.46
5.0.30.0070.0438.30
5.0.20.0000.0278.28
5.0.10.0070.0338.19
5.0.00.0100.0578.16
4.4.90.0030.0336.73
4.4.80.0000.0376.73
4.4.70.0000.0376.73
4.4.60.0070.0306.73
4.4.50.0070.0306.73
4.4.40.0070.0536.73
4.4.30.0030.0206.73
4.4.20.0000.0376.73
4.4.10.0030.0176.73
4.4.00.0030.0406.73
4.3.110.0030.0336.73
4.3.100.0000.0236.73
4.3.90.0000.0376.73
4.3.80.0100.0476.73
4.3.70.0000.0376.73
4.3.60.0000.0376.73
4.3.50.0030.0306.73
4.3.40.0030.0476.73
4.3.30.0000.0336.73
4.3.20.0000.0376.73
4.3.10.0000.0276.73
4.3.00.0000.0236.73

preferences:
43.98 ms | 401 KiB | 5 Q