3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Foo { public function getData() { return [ 'a' => [ 'fooa1' => 'bara1', 'fooa2' => 'bara2', 'fooa3' => 'bara3', 'parent' => '0' ], 'b' => [ 'foob1' => 'barb1', 'foob2' => 'barb2', 'foob3' => 'barb3', 'parent' => '0' ], 'c' => [ 'fooc1' => 'barc1', 'fooc2' => 'barc2', 'fooc3' => 'barc3', 'parent' => 'b' ], 'd' => [ 'food1' => 'bard1', 'food2' => 'bard2', 'food3' => 'bard3', 'parent' => 'a' ], 'e' => [ 'fooe1' => 'bare1', 'fooe2' => 'bare2', 'fooe3' => 'bare3', 'parent' => 'c' ], ]; } public function getDataPattern() { return [ 'a' => [ 'fooa1' => 'bara1', 'fooa2' => 'bara2', 'fooa3' => 'bara3', 'children' => [ 'd' => [ 'food1' => 'bard1', 'food2' => 'bard2', 'food3' => 'bard3', 'parent' => 'a' ], ] ], 'b' => [ 'foob1' => 'barb1', 'foob2' => 'barb2', 'foob3' => 'barb3', 'children' => [ 'c' => [ 'fooc1' => 'barc1', 'fooc2' => 'barc2', 'fooc3' => 'barc3', 'parent' => 'b', 'children' => [ 'e' => [ 'fooe1' => 'bare1', 'fooe2' => 'bare2', 'fooe3' => 'bare3', 'parent' => 'c' ], ] ], ] ], ]; } public function transformArrayToPattern(){ $data = $this->getData(); $nodes = []; foreach($data as $node_name => $node_data){ if(!isset($nodes[$node_data['parent']])) $nodes[$node_data['parent']] = []; $nodes[$node_data['parent']][] = $node_name; } //print_r($nodes); $result = []; foreach($nodes['0'] as $node_name){ $result[$node_name] = $this->dfs($node_name,$nodes,$data); unset($result[$node_name]['parent']); // to unset parent 0 } return $result; } private function dfs($node_name,$nodes,$data){ if(!isset($nodes[$node_name])){ return $data[$node_name]; } $children = []; foreach($nodes[$node_name] as $kid_name){ $children[$kid_name] = $this->dfs($kid_name,$nodes,$data); } return array_merge($data[$node_name],['children' => $children]); } } $o = new Foo(); print_r($o->transformArrayToPattern());

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.30.0120.00719.39
8.5.20.0090.00819.52
8.5.10.0090.00718.98
8.5.00.0140.00820.16
8.4.180.0120.01023.85
8.4.170.0130.01123.79
8.4.160.0130.00823.93
8.4.150.0090.00516.90
8.4.140.0140.00617.52
8.4.130.0130.00818.59
8.4.120.0110.00824.16
8.4.110.0160.00618.89
8.4.100.0070.00219.09
8.4.90.0020.00720.56
8.4.80.0150.00519.02
8.4.70.0110.00917.95
8.4.60.0090.01118.77
8.4.50.0050.00818.84
8.4.40.0060.01217.78
8.4.30.0080.00318.79
8.4.20.0080.00317.90
8.4.10.0130.01017.92
8.3.300.0120.00822.64
8.3.290.0120.01020.87
8.3.280.0150.00518.40
8.3.270.0160.00316.61
8.3.260.0110.01016.89
8.3.250.0140.00718.97
8.3.240.0120.00717.03
8.3.230.0120.00716.72
8.3.220.0040.00418.80
8.3.210.0110.01018.30
8.3.200.0030.00616.65
8.3.190.0140.00617.08
8.3.180.0110.00717.12
8.3.170.0090.00620.81
8.3.160.0160.00316.38
8.3.150.0130.00616.59
8.3.140.0120.00317.43
8.3.130.0070.01018.45
8.3.120.0060.00318.95
8.3.110.0050.00320.94
8.3.100.0090.00016.74
8.3.90.0000.00826.77
8.3.80.0070.00319.36
8.3.70.0120.00316.74
8.3.60.0170.00318.32
8.3.50.0090.00823.62
8.3.40.0120.00918.93
8.3.30.0090.00618.67
8.3.20.0040.00421.95
8.3.10.0040.00422.00
8.3.00.0050.00321.73
8.2.300.0160.00722.32
8.2.290.0080.01120.43
8.2.280.0090.01118.39
8.2.270.0040.01516.44
8.2.260.0140.00416.89
8.2.250.0070.00716.91
8.2.240.0060.00617.21
8.2.230.0000.00822.58
8.2.220.0060.00324.06
8.2.210.0080.01126.77
8.2.200.0000.00918.88
8.2.190.0110.00718.54
8.2.180.0100.01018.50
8.2.170.0090.00622.96
8.2.160.0070.00722.06
8.2.150.0000.00824.18
8.2.140.0080.00024.66
8.2.130.0000.00826.16
8.2.120.0040.00419.95
8.2.110.0100.00020.95
8.2.100.0080.00319.25
8.2.90.0080.00017.88
8.2.80.0050.00320.50
8.2.70.0090.00417.75
8.2.60.0000.00818.16
8.2.50.0040.00418.07
8.2.40.0030.00520.07
8.2.30.0040.00419.54
8.2.20.0000.00718.22
8.2.10.0000.01119.46
8.2.00.0040.00419.34
8.1.340.0110.00817.46
8.1.330.0100.00922.00
8.1.320.0120.00817.89
8.1.310.0080.00016.13
8.1.300.0030.00720.34
8.1.290.0080.00030.84
8.1.280.0140.00725.92
8.1.270.0050.00322.18
8.1.260.0050.00326.35
8.1.250.0000.00828.09
8.1.240.0040.00422.02
8.1.230.0060.00620.94
8.1.220.0030.00617.74
8.1.210.0050.00319.04
8.1.200.0100.00017.35
8.1.190.0040.00417.35
8.1.180.0060.00318.10
8.1.170.0000.00818.64
8.1.160.0050.00318.93
8.1.150.0000.00818.92
8.1.140.0040.00420.87
8.1.130.0030.00720.21
8.1.120.0030.00517.43
8.1.110.0050.00217.38
8.1.100.0080.00017.52
8.1.90.0000.00917.51
8.1.80.0000.00817.39
8.1.70.0030.00317.48
8.1.60.0040.00417.47
8.1.50.0050.00317.52
8.1.40.0000.00817.49
8.1.30.0040.00417.67
8.1.20.0050.00317.62
8.1.10.0000.00817.41
8.1.00.0080.00017.34
8.0.300.0050.00520.12
8.0.290.0070.00016.63
8.0.280.0080.00018.39
8.0.270.0030.00318.03
8.0.260.0040.00420.16
8.0.250.0040.00416.90
8.0.240.0000.00816.97
8.0.230.0030.00316.91
8.0.220.0040.00416.92
8.0.210.0030.00516.95
8.0.200.0040.00416.95
8.0.190.0040.00417.01
8.0.180.0040.00416.95
8.0.170.0040.00416.85
8.0.160.0000.00716.88
8.0.150.0040.00716.80
8.0.140.0000.00716.85
8.0.130.0050.00013.28
8.0.120.0040.00416.87
8.0.110.0070.00016.79
8.0.100.0040.00417.04
8.0.90.0000.00816.89
8.0.80.0080.01116.92
8.0.70.0040.00416.80
8.0.60.0000.00716.80
8.0.50.0040.00417.04
8.0.30.0070.01317.15
8.0.20.0060.01417.25
8.0.10.0000.00716.93
8.0.00.0120.01216.79
7.4.330.0000.00516.71
7.4.320.0030.00316.47
7.4.300.0000.00716.68
7.4.290.0070.00016.64
7.4.280.0070.00016.43
7.4.270.0030.00316.66
7.4.260.0030.00313.36
7.4.250.0030.00316.57
7.4.240.0030.00316.61
7.4.230.0000.00716.57
7.4.220.0030.00316.61
7.4.210.0110.00316.61
7.4.200.0030.00316.36
7.4.130.0090.00916.54
7.4.120.0100.01316.51
7.4.110.0090.01216.74
7.4.100.0070.01416.55
7.4.90.0130.01016.53
7.4.80.0060.01219.39
7.4.70.0100.00616.57
7.4.60.0130.00316.54
7.4.50.0090.00616.56
7.4.40.0060.00916.41
7.4.20.0120.00916.44
7.4.10.0080.01416.59
7.4.00.0130.00716.55
7.3.330.0030.00616.39
7.3.320.0030.00313.39
7.3.310.0050.00316.22
7.3.300.0050.00216.32
7.3.290.0080.00816.39
7.3.260.0130.00316.41
7.3.240.0090.00716.42
7.3.230.0070.01116.34
7.3.210.0140.00416.48
7.3.200.0060.00916.42
7.3.190.0090.00616.47
7.3.180.0180.00316.64
7.3.170.0070.01316.64
7.3.160.0150.00316.49
7.3.130.0090.01216.20
7.3.120.0110.00716.36
7.3.110.0100.01016.19
7.3.100.0080.00816.29
7.3.90.0090.00616.38
7.3.80.0140.00316.70
7.3.70.0100.00716.43
7.3.60.0200.00716.33
7.3.50.0100.01016.34
7.3.40.0070.01416.41
7.3.30.0040.01116.34
7.3.20.0150.00616.19
7.3.10.0070.01016.40
7.3.00.0070.01116.45
7.2.330.0070.01116.51
7.2.320.0070.01416.51
7.2.310.0090.01516.86
7.2.300.0030.01716.93
7.2.290.0120.00616.80
7.2.260.0160.00316.43
7.2.250.0070.01116.52
7.2.240.0060.01516.29
7.2.230.0100.01316.41
7.2.220.0090.01216.49
7.2.210.0030.01416.60
7.2.200.0060.01016.62
7.2.190.0130.00616.61
7.2.180.0060.01916.70
7.2.170.0070.01316.70
7.2.160.0060.01316.55
7.2.150.0120.00916.61
7.2.140.0060.01316.70
7.2.130.0140.00416.51
7.2.120.0070.01116.86
7.2.110.0050.01416.64
7.2.100.0100.01116.61
7.2.90.0070.01416.54
7.2.80.0000.01816.55
7.2.70.0100.01116.52
7.2.60.0140.00316.60
7.2.50.0070.01016.74
7.2.40.0070.01516.73
7.2.30.0560.00716.81
7.2.20.0070.01416.61
7.2.10.0120.00616.63
7.2.00.0030.01716.48

preferences:
56.14 ms | 1799 KiB | 5 Q