3v4l.org

run code in 300+ PHP versions simultaneously
<?php function orderBeforeArray($name, $destination, $list) { // reindex the array so there are no gaps $list = array_values($list); $oldpos = array_search($name, $list); if (false === $oldpos) { throw new ItemNotFoundException("$name is not a child of this node"); } if ($destination == null) { // null means move to end unset($list[$oldpos]); $list[] = $name; } else { // insert before element $destination $newpos = array_search($destination, $list); if ($newpos === false) { throw new ItemNotFoundException("$destination is not a child of this node"); } if ($oldpos < $newpos) { // we first unset, the position will change by one $newpos--; } unset($list[$oldpos]); array_splice($list, $newpos, 0, $name); } return $list; } $old = ['one', 'two', 'three', 'four']; $new = ['one', 'three', 'two']; $reorders = []; //check for deleted items $newIndex = array_flip($new); foreach ($old as $key => $value) { if (!isset($newIndex[$value])) { unset($old[$key]); } } // reindex the arrays to avoid holes in the indexes $old = array_values($old); $new = array_values($new); $len = count($new) - 1; $oldIndex = array_flip($old); //go backwards on the new node order and arrange them this way for ($i = $len; $i >= 0; $i--) { //get the name of the child node $current = $new[$i]; //check if it's not the last node if (isset($new[$i + 1])) { // get the name of the next node $next = $new[$i + 1]; //if in the old order $c and next are not neighbors already, do the reorder command if ($oldIndex[$current] + 1 != $oldIndex[$next]) { $reorders[$current] = $next; $old = orderBeforeArray($current, $next, $old); $oldIndex = array_flip($old); } } else { //check if it's not already at the end of the nodes if ($oldIndex[$current] != $len) { $reorders[$current] = null; $old = orderBeforeArray($current, null, $old); $oldIndex = array_flip($old); } } } var_dump($reorders);

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.00916.63
8.3.50.0130.00718.44
8.3.40.0040.01118.82
8.3.30.0070.01418.84
8.3.20.0110.00420.38
8.3.10.0050.00322.13
8.3.00.0040.00423.64
8.2.180.0070.01025.92
8.2.170.0170.00322.96
8.2.160.0160.00320.39
8.2.150.0060.00324.18
8.2.140.0050.00324.66
8.2.130.0050.00319.45
8.2.120.0050.00326.35
8.2.110.0080.00321.18
8.2.100.0000.01218.13
8.2.90.0000.00819.36
8.2.80.0000.00917.97
8.2.70.0000.00817.50
8.2.60.0110.00018.05
8.2.50.0000.00818.22
8.2.40.0040.00420.59
8.2.30.0000.01021.11
8.2.20.0040.00418.06
8.2.10.0000.00818.12
8.2.00.0080.00018.14
8.1.280.0070.00725.92
8.1.270.0000.00823.97
8.1.260.0000.00826.35
8.1.250.0020.00528.09
8.1.240.0080.00420.78
8.1.230.0000.01120.32
8.1.220.0000.00817.74
8.1.210.0040.00418.77
8.1.200.0000.00917.25
8.1.190.0040.00417.35
8.1.180.0060.00318.10
8.1.170.0060.00318.54
8.1.160.0000.00718.95
8.1.150.0030.00520.20
8.1.140.0040.00419.51
8.1.130.0000.00719.00
8.1.120.0040.00417.49
8.1.110.0040.00417.47
8.1.100.0000.00817.43
8.1.90.0070.00317.53
8.1.80.0040.00417.52
8.1.70.0030.00317.44
8.1.60.0000.00817.64
8.1.50.0000.00917.56
8.1.40.0000.00717.57
8.1.30.0000.00917.67
8.1.20.0000.00817.66
8.1.10.0000.00817.59
8.1.00.0020.00517.41
8.0.300.0080.00018.87
8.0.290.0070.00016.75
8.0.280.0030.00318.47
8.0.270.0000.00717.27
8.0.260.0000.00718.38
8.0.250.0000.00717.04
8.0.240.0030.00316.88
8.0.230.0040.00416.88
8.0.220.0000.00716.89
8.0.210.0040.00416.79
8.0.200.0030.00316.86
8.0.190.0050.00316.86
8.0.180.0050.00316.92
8.0.170.0040.00416.99
8.0.160.0060.00316.93
8.0.150.0030.00616.86
8.0.140.0040.00416.86
8.0.130.0060.00013.38
8.0.120.0000.00816.87
8.0.110.0050.00216.96
8.0.100.0000.00816.73
8.0.90.0030.00616.84
8.0.80.0030.01116.87
8.0.70.0040.00416.85
8.0.60.0040.00416.93
8.0.50.0030.00516.88
8.0.30.0130.00517.18
8.0.20.0130.00617.40
8.0.10.0000.00716.84
8.0.00.0030.01616.88
7.4.330.0060.00016.59
7.4.320.0020.00516.59
7.4.300.0000.00616.63
7.4.290.0030.00316.51
7.4.280.0040.00416.50
7.4.270.0000.00816.52
7.4.260.0030.00316.52
7.4.250.0040.00416.61
7.4.240.0070.00016.67
7.4.230.0060.00316.52
7.4.220.0130.01316.53
7.4.210.0080.00616.68
7.4.200.0030.00316.37
7.4.160.0090.00616.56
7.4.150.0100.00717.40
7.4.140.0100.00817.86
7.4.130.0070.01116.50
7.4.120.0080.01116.51
7.4.110.0060.01816.65
7.4.100.0140.00416.40
7.4.90.0030.01316.50
7.4.80.0090.01319.39
7.4.70.0000.01716.61
7.4.60.0090.01616.46
7.4.50.0060.00616.47
7.4.40.0170.00716.42
7.4.30.0090.01216.76
7.4.00.0000.01614.99
7.3.330.0000.00613.38
7.3.320.0000.00513.32
7.3.310.0030.00316.26
7.3.300.0040.00416.32
7.3.290.0040.01016.36
7.3.280.0090.00816.37
7.3.270.0090.00917.40
7.3.260.0090.00816.54
7.3.250.0100.00916.45
7.3.240.0080.00916.45
7.3.230.0090.00916.44
7.3.210.0070.01016.71
7.3.200.0030.01316.72
7.3.190.0030.01316.36
7.3.180.0100.00716.39
7.3.170.0060.00916.32
7.3.160.0120.00616.67
7.2.330.0090.00916.42
7.2.320.0140.01216.56
7.2.310.0100.01416.57
7.2.300.0080.00816.77
7.2.290.0090.00916.85
7.2.120.0230.00416.40
7.2.110.0190.00816.53
7.2.100.0170.01316.62
7.2.90.0170.00016.70
7.2.80.0170.00916.64
7.2.70.0270.01016.86
7.2.60.0080.00916.98
7.2.50.0260.00717.00
7.2.40.0270.00616.71
7.2.30.0250.00616.99
7.2.20.0270.00016.61
7.2.10.0220.00717.13
7.2.00.0150.00818.32
7.1.240.0160.00315.70
7.1.230.0080.00815.55
7.1.220.0280.00315.74
7.1.210.0240.00315.68
7.1.200.0110.00815.82
7.1.190.0100.00715.68
7.1.180.0260.00015.70
7.1.170.0260.00315.76
7.1.160.0230.00715.58
7.1.150.0120.01215.79
7.1.140.0160.00715.89
7.1.130.0180.00615.92
7.1.120.0180.00717.21
7.1.110.0140.00917.05
7.1.100.0110.00616.99
7.1.90.0110.00617.28
7.1.80.0160.00817.31
7.1.70.0130.00516.82
7.1.60.0190.01128.67
7.1.50.0270.01128.45
7.1.40.0170.00828.16
7.1.30.0170.01228.23
7.1.20.0160.01228.27
7.1.10.0100.01116.45
7.1.00.0190.00616.35
7.0.320.0220.00415.12
7.0.310.0160.00815.19
7.0.300.0310.00015.34
7.0.290.0050.01215.30
7.0.280.0180.00715.41
7.0.270.0140.01115.36
7.0.260.0100.00616.84
7.0.250.0130.00516.66
7.0.240.0140.00816.71
7.0.230.0070.00616.93
7.0.220.0230.00817.01
7.0.210.0120.00916.25
7.0.200.0100.00716.21
7.0.190.0080.00616.30
7.0.180.0080.00715.83
7.0.170.0120.00915.95
7.0.160.0180.00515.95
7.0.150.0120.00616.10
7.0.140.0080.00915.98
7.0.130.0110.00616.11
7.0.120.0160.00416.23
7.0.110.0080.00915.92
7.0.100.0120.00715.99
7.0.90.0070.01216.01
7.0.80.0090.01016.22
7.0.70.0110.00816.00
7.0.60.0070.00815.91
7.0.50.0160.00816.13
7.0.40.0060.00915.59
7.0.30.0080.00615.54
7.0.20.0060.01015.48
7.0.10.0070.00915.42
7.0.00.0120.00314.87
5.6.380.0090.00914.76
5.6.370.0150.00214.62
5.6.360.0060.01214.34
5.6.350.0150.00314.71
5.6.340.0170.00014.25
5.6.330.0160.00014.79
5.6.320.0120.00614.39
5.6.310.0090.00914.76
5.6.300.0080.05118.68
5.6.290.0090.04018.68
5.6.280.0110.03618.77
5.6.270.0120.04418.82
5.6.260.0110.04118.68
5.6.250.0110.04918.69
5.6.240.0160.03818.70
5.6.230.0090.04218.71
5.6.220.0130.03518.74
5.6.210.0080.04118.67
5.6.200.0110.04218.61
5.6.190.0120.03618.88
5.6.180.0140.03518.58
5.6.170.0090.04218.75
5.6.160.0170.03718.72
5.6.150.0120.03718.73
5.6.140.0130.03918.71
5.6.130.0150.03418.68
5.6.120.0110.04218.75
5.6.110.0060.04518.78
5.6.100.0170.03318.79
5.6.90.0150.03818.74
5.6.80.0090.04118.37
5.6.70.0090.03918.33
5.6.60.0160.03418.31
5.6.50.0100.03718.32
5.6.40.0060.04018.23
5.6.30.0060.04518.36
5.6.20.0130.04418.29
5.6.10.0110.03618.28
5.6.00.0130.03318.21
5.5.380.0110.03814.44
5.5.370.0170.03414.47
5.5.360.0120.02814.44
5.5.350.0100.02714.56
5.5.340.0160.02314.66
5.5.330.0060.03314.57
5.5.320.0120.02714.66
5.5.310.0070.03314.76
5.5.300.0140.03614.77
5.5.290.0140.02814.81
5.5.280.0100.03014.46
5.5.270.0150.02414.74
5.5.260.0130.02814.41
5.5.250.0100.03314.51
5.5.240.0150.03514.27
5.5.230.0080.03214.40
5.5.220.0160.02114.41
5.5.210.0070.03014.34
5.5.200.0070.03214.16
5.5.190.0140.02614.41
5.5.180.0080.03214.22
5.5.170.0130.00014.09
5.5.160.0120.02414.21
5.5.150.0050.03214.28
5.5.140.0120.02614.25
5.5.130.0140.02514.24
5.5.120.0140.02514.10
5.5.110.0100.03914.09
5.5.100.0180.02014.19
5.5.90.0120.02314.24
5.5.80.0200.01814.20
5.5.70.0090.03714.37
5.5.60.0110.02814.22
5.5.50.0140.02414.25
5.5.40.0060.03514.10
5.5.30.0100.03114.36
5.5.20.0070.03014.18
5.5.10.0160.02314.27
5.5.00.0170.02214.33
5.4.450.0120.03115.33
5.4.440.0090.03215.43
5.4.430.0120.03015.32
5.4.420.0070.03215.42
5.4.410.0130.02615.14
5.4.400.0070.03515.06
5.4.390.0110.02914.96
5.4.380.0080.02915.17
5.4.370.0150.02315.07
5.4.360.0210.02615.06
5.4.350.0100.02814.98
5.4.340.0100.03115.21
5.4.330.0000.01111.29
5.4.320.0100.03515.14
5.4.310.0100.02815.14
5.4.300.0110.02615.16
5.4.290.0030.03314.96
5.4.280.0160.02315.12
5.4.270.0080.03215.15
5.4.260.0080.03915.20
5.4.250.0120.02815.08
5.4.240.0100.03615.05
5.4.230.0100.03015.26
5.4.220.0130.02715.17
5.4.210.0050.03315.07
5.4.200.0120.03215.05
5.4.190.0060.03115.04
5.4.180.0120.02515.23
5.4.170.0110.02715.03
5.4.160.0180.02815.10
5.4.150.0140.03115.13
5.4.140.0150.03314.00
5.4.130.0130.02414.04
5.4.120.0070.02813.93
5.4.110.0150.02313.80
5.4.100.0100.02714.04
5.4.90.0070.03013.82
5.4.80.0150.02214.01
5.4.70.0100.02613.88
5.4.60.0070.02913.94
5.4.50.0080.02713.90
5.4.40.0080.02913.93
5.4.30.0100.02313.91
5.4.20.0110.03113.86
5.4.10.0140.02813.94
5.4.00.0080.03513.46
5.3.290.0070.03113.03
5.3.280.0080.02912.99
5.3.270.0110.03812.96
5.3.260.0120.03212.98
5.3.250.0100.03112.91
5.3.240.0110.03412.78
5.3.230.0110.02712.99
5.3.220.0110.03212.92
5.3.210.0100.02812.92
5.3.200.0080.03212.97
5.3.190.0110.02912.95
5.3.180.0140.02112.98
5.3.170.0110.03512.86
5.3.160.0070.02712.86
5.3.150.0110.02412.87
5.3.140.0150.01812.96
5.3.130.0070.02912.96
5.3.120.0120.03512.97
5.3.110.0080.03212.91
5.3.100.0090.03012.71
5.3.90.0130.02412.69
5.3.80.0110.02512.66
5.3.70.0140.02012.72
5.3.60.0070.02812.63
5.3.50.0180.02712.61
5.3.40.0080.02712.66
5.3.30.0050.02612.53
5.3.20.0130.02212.50
5.3.10.0070.03712.50
5.3.00.0090.02712.47
5.2.170.0110.02811.13
5.2.160.0080.02111.15
5.2.150.0050.02811.22
5.2.140.0090.02011.23
5.2.130.0090.02711.19
5.2.120.0060.03011.24
5.2.110.0050.03211.17
5.2.100.0110.02611.20
5.2.90.0090.02911.19
5.2.80.0090.02011.20
5.2.70.0060.02611.09
5.2.60.0170.01411.22
5.2.50.0080.02011.16
5.2.40.0080.02611.00
5.2.30.0050.02211.18
5.2.20.0080.02211.03
5.2.10.0100.01810.98
5.2.00.0090.01910.94
5.1.60.0060.02010.49
5.1.50.0050.01910.57
5.1.40.0080.02210.67
5.1.30.0050.02210.85
5.1.20.0070.01910.73
5.1.10.0050.02110.72
5.1.00.0100.01810.68
5.0.50.0030.0179.83
5.0.40.0040.0179.87
5.0.30.0080.0209.73
5.0.20.0040.0169.81
5.0.10.0030.0179.73
5.0.00.0080.0189.73
4.4.90.0080.0139.73
4.4.80.0050.0119.73
4.4.70.0020.0159.73
4.4.60.0090.0069.73
4.4.50.0020.0149.73
4.4.40.0040.0259.73
4.4.30.0050.0169.73
4.4.20.0030.0179.73
4.4.10.0040.0129.73
4.4.00.0050.0179.73
4.3.110.0050.0129.73
4.3.100.0050.0119.73
4.3.90.0040.0139.73
4.3.80.0060.0159.73
4.3.70.0020.0169.73
4.3.60.0050.0089.73
4.3.50.0090.0099.73
4.3.40.0040.0169.73
4.3.30.0020.0139.73
4.3.20.0030.0119.73
4.3.10.0040.0129.73
4.3.00.0010.0149.73

preferences:
36.91 ms | 400 KiB | 5 Q