3v4l.org

run code in 300+ PHP versions simultaneously
<?php $data = [ [ 'table' => 'test', 'parent_table' => NULL, ], [ 'table' => 'test', 'parent_table' => NULL, ], [ 'table' => 'test2', 'parent_table' => 'test', ], [ 'table' => 'test4', 'parent_table' => NULL, ], [ 'table' => 'test5', 'parent_table' => 'test3', ], [ 'table' => 'test6', 'parent_table' => 'test5', ], [ 'table' => 'test3', 'parent_table' => 'test', ], ]; function reorderHierarchy($data){ $hierarchy = []; $top_level_parents = []; foreach($data as $each_data){ $hierarchy[$each_data['table']] = array(); if(is_null($each_data['parent_table'])){ if(!isset($top_level_parents[$each_data['table']])){ $top_level_parents[$each_data['table']] = 0; } $top_level_parents[$each_data['table']]++; } } foreach($data as $each_data){ if(!is_null($each_data['parent_table'])){ $hierarchy[$each_data['parent_table']][] = $each_data['table']; } } $result = []; traverseHierarchy($hierarchy,$top_level_parents,$result); return $result; } function traverseHierarchy($hierarchy,$top_level_parents,&$result){ foreach($top_level_parents as $each_parent => $occurrences){ while($occurrences-- > 0){ $result[] = [ 'table' => $each_parent, 'parent_table' => NULL ]; } traverseChildren($hierarchy,$each_parent,$result); } } function traverseChildren($hierarchy,$parent,&$result){ foreach($hierarchy[$parent] as $each_child){ $result[] = [ 'table' => $each_child, 'parent_table' => $parent ]; traverseChildren($hierarchy,$each_child,$result); } } foreach(reorderHierarchy($data) as $each_data){ echo $each_data['table']," , ",(is_null($each_data['parent_table']) ? "NULL" : $each_data['parent_table']),PHP_EOL; }

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.10.0110.00916.61
8.5.00.0120.01120.20
8.4.160.0180.00721.59
8.4.150.0030.00014.05
8.4.140.0140.01017.73
8.4.130.0140.00618.61
8.4.120.0030.00624.16
8.4.110.0120.00520.48
8.4.100.0130.00717.77
8.4.90.0080.00220.79
8.4.80.0130.00818.72
8.4.70.0090.00017.85
8.4.60.0140.00720.59
8.4.50.0140.00918.57
8.4.40.0180.00419.35
8.4.30.0130.00717.63
8.4.20.0130.00720.54
8.4.10.0040.00417.72
8.3.280.0130.00918.41
8.3.270.0160.00716.69
8.3.260.0130.00716.70
8.3.250.0110.00518.80
8.3.240.0090.01017.15
8.3.230.0120.00816.55
8.3.220.0130.00618.85
8.3.210.0120.00516.79
8.3.200.0030.00516.62
8.3.190.0110.01017.39
8.3.180.0130.00616.88
8.3.170.0090.00919.09
8.3.160.0130.00616.77
8.3.150.0110.00720.84
8.3.140.0180.00016.69
8.3.130.0090.00018.48
8.3.120.0100.00020.72
8.3.110.0060.00320.94
8.3.100.0040.00424.06
8.3.90.0060.00926.77
8.3.80.0100.00017.97
8.3.70.0120.00616.74
8.3.60.0100.01018.43
8.3.50.0140.00718.44
8.3.40.0090.00618.76
8.3.30.0130.01018.67
8.3.20.0000.00720.94
8.3.10.0040.00421.63
8.3.00.0040.00421.73
8.2.290.0100.00820.42
8.2.280.0100.00918.45
8.2.270.0000.01919.08
8.2.260.0080.00020.14
8.2.250.0050.00516.43
8.2.240.0090.00317.37
8.2.230.0090.00022.58
8.2.220.0080.00037.54
8.2.210.0110.00726.77
8.2.200.0070.00318.17
8.2.190.0060.00916.63
8.2.180.0070.01416.49
8.2.170.0110.00422.96
8.2.160.0140.00019.51
8.2.150.0040.00424.18
8.2.140.0050.00324.66
8.2.130.0000.00719.33
8.2.120.0000.00726.35
8.2.110.0030.00622.10
8.2.100.0120.00017.95
8.2.90.0060.00317.94
8.2.80.0040.00418.16
8.2.70.0060.00318.04
8.2.60.0000.00818.28
8.2.50.0040.00418.10
8.2.40.0040.00419.33
8.2.30.0090.00019.50
8.2.20.0040.00418.09
8.2.10.0040.00419.36
8.2.00.0000.00818.22
8.1.330.0040.00421.98
8.1.320.0160.00516.31
8.1.310.0150.00316.82
8.1.300.0060.00318.43
8.1.290.0030.00630.84
8.1.280.0210.00025.92
8.1.270.0060.00322.14
8.1.260.0080.00026.35
8.1.250.0040.00428.09
8.1.240.0000.00823.96
8.1.230.0080.00422.54
8.1.220.0040.00417.79
8.1.210.0040.00418.97
8.1.200.0120.00017.35
8.1.190.0040.00417.36
8.1.180.0080.00018.10
8.1.170.0080.00018.66
8.1.160.0050.00318.92
8.1.150.0040.00418.96
8.1.140.0050.00318.93
8.1.130.0000.00920.19
8.1.120.0000.00717.40
8.1.110.0030.00617.46
8.1.100.0060.00317.58
8.1.90.0000.00817.40
8.1.80.0040.00417.48
8.1.70.0060.00317.40
8.1.60.0000.01017.52
8.1.50.0040.00717.41
8.1.40.0030.00617.46
8.1.30.0040.00417.52
8.1.20.0030.00617.75
8.1.10.0050.00317.61
8.1.00.0040.00417.57
8.0.300.0080.00019.80
8.0.290.0050.00216.88
8.0.280.0030.00718.50
8.0.270.0040.00416.87
8.0.260.0030.00318.40
8.0.250.0060.00317.03
8.0.240.0030.00616.99
8.0.230.0000.00716.97
8.0.220.0020.00516.80
8.0.210.0030.00316.92
8.0.200.0050.00317.04
8.0.190.0040.00416.99
8.0.180.0050.00316.98
8.0.170.0040.00417.00
8.0.160.0080.00016.86
8.0.150.0030.00716.84
8.0.140.0000.00716.89
8.0.130.0050.00013.38
8.0.120.0000.00716.89
8.0.110.0080.00016.86
8.0.100.0050.00216.85
8.0.90.0040.00416.98
8.0.80.0040.01416.92
8.0.70.0000.00716.82
8.0.60.0000.00816.98
8.0.50.0020.00516.73
8.0.30.0100.00917.28
8.0.20.0090.01317.40
8.0.10.0000.00717.11
8.0.00.0090.00916.77
7.4.330.0050.00015.55
7.4.320.0000.00616.62
7.4.300.0000.00616.60
7.4.290.0000.00716.55
7.4.280.0040.00416.67
7.4.270.0000.00716.66
7.4.260.0000.00716.63
7.4.250.0000.00716.66
7.4.240.0040.00416.64
7.4.230.0070.00016.65
7.4.220.0030.00616.67
7.4.210.0080.00716.58
7.4.200.0030.00316.39
7.4.160.0100.00716.62
7.4.140.0120.00517.86
7.4.130.0140.00416.66
7.4.120.0070.01116.59
7.4.110.0090.01616.52
7.4.100.0160.00316.62
7.4.90.0090.00916.54
7.4.80.0180.00419.39
7.4.70.0060.01216.46
7.4.60.0110.00716.59
7.4.50.0100.00316.41
7.4.40.0100.00716.55
7.4.00.0110.00414.84
7.3.330.0030.00313.50
7.3.320.0000.00613.20
7.3.310.0070.00016.29
7.3.300.0040.00416.43
7.3.290.0040.00416.38
7.3.280.0100.01216.44
7.3.260.0110.01016.49
7.3.240.0130.00716.71
7.3.230.0070.01016.63
7.3.210.0120.00616.36
7.3.200.0080.01216.61
7.3.190.0070.01016.28
7.3.180.0030.01316.52
7.3.170.0100.00716.35
7.3.160.0100.00716.76
7.3.120.0100.01014.94
7.3.110.0110.00714.95
7.3.100.0110.00414.89
7.3.90.0070.01015.02
7.3.80.0100.00314.96
7.3.70.0060.00914.93
7.3.60.0040.00814.96
7.3.50.0040.00715.01
7.3.40.0000.00814.82
7.3.30.0030.00614.84
7.3.20.0070.00716.67
7.3.10.0250.00815.89
7.3.00.0190.00715.52
7.2.330.0090.00916.63
7.2.320.0090.00916.76
7.2.310.0040.01516.57
7.2.300.0120.00416.36
7.2.290.0080.00816.80
7.2.250.0080.01115.34
7.2.240.0130.00715.05
7.2.230.0060.00614.86
7.2.220.0030.01415.25
7.2.210.0040.01115.02
7.2.200.0030.00615.15
7.2.190.0000.01215.24
7.2.180.0060.00615.12
7.2.170.0090.00315.10
7.2.130.0440.01315.16
7.2.120.0340.00715.34
7.2.110.0430.01015.16
7.2.100.0470.00715.25
7.2.90.0330.01015.18
7.2.80.0380.00315.15
7.2.70.0550.00315.22
7.2.60.0530.00415.16
7.2.50.0500.00715.22
7.2.40.0540.00315.23
7.2.30.0500.00815.19
7.2.20.0520.00715.14
7.2.10.0480.00715.41
7.2.00.0500.01715.20
7.1.330.0070.00715.95
7.1.320.0110.00715.87
7.1.310.0030.01315.94
7.1.300.0060.00615.98
7.1.290.0030.01015.84
7.1.280.0030.01015.69
7.1.270.0100.00015.59
7.1.260.0040.00715.60
7.1.250.0500.00014.11

preferences:
41.81 ms | 403 KiB | 5 Q