3v4l.org

run code in 500+ PHP versions simultaneously
<?php $inputArray = array ( 0 => array ( 'id_file' => '96', 'file_name' => 'Важный документ.docx', 'file_directory' => 'АК\\Документы', 'region' => 'Для работы', 'directory' => 'АК\\Документы\\Важный документ.docx', ), 1 => array ( 'id_file' => '97', 'file_name' => 'июнь_2020.docx', 'file_directory' => 'АК\\Документы', 'region' => 'Для работы', 'directory' => 'АК\\Документы\\июнь_2020.docx', ), 2 => array ( 'id_file' => '104', 'file_name' => '111222.pdf', 'file_directory' => 'АК\\Документы\\Почта', 'region' => 'Для работы', 'directory' => 'АК\\Документы\\Почта\\111222.pdf', ), 3 => array ( 'id_file' => '110', 'file_name' => '111222sss.pdf', 'file_directory' => 'АК\\Документы\\Почта', 'region' => 'Для работы', 'directory' => 'АК\\Документы\\Почта\\111222sss.pdf', ), 4 => array ( 'id_file' => '116', 'file_name' => 'asdasd1.pdf', 'file_directory' => 'АК\\Документы\\УК', 'region' => 'Для работы', 'directory' => 'АК\\Документы\\УК\\asdasd1.pdf', ), 5 => array ( 'id_file' => '128', 'file_name' => '111222sss.pdf', 'file_directory' => 'ДК\\Картинки\\УК', 'region' => 'Для отдыха', 'directory' => 'ДК\\Картинки\\УК\\111222sss.pdf', ), 6 => array ( 'id_file' => '128', 'file_name' => 'asdasd2.pdf', 'file_directory' => 'АК\\Приказы', 'region' => 'Для работы', 'directory' => 'АК\\Приказы\\asdasd2.pdf', ), ); $list = array_map(function($item){ $path = explode('\\', $item['file_directory']); array_splice($path, 1, 0, $item['region']); return array( 'id' => $item['id_file'], 'path' => $path, 'name' => $item['file_name'], ); }, $inputArray); function buildTree($items, $prefix = []) { $res = []; $visited = []; foreach($items as $item) { if (count($item['path']) < count($prefix)) continue; if (array_slice($item['path'], 0, count($prefix)) !== $prefix) continue; // echo json_encode([$prefix, $item], JSON_UNESCAPED_UNICODE), PHP_EOL; $node = []; if (count($item['path']) > count($prefix)) { $curPath = $item['path'][count($prefix)]; $nextPrefix = array_merge($prefix, [$curPath]); $strPrefix = implode('\\', $nextPrefix); if ($visited[$strPrefix] ?? false) continue; $node['type'] = 'folder'; $node['path'] = $strPrefix; $node['name'] = $curPath; $node['children'] = buildTree($items, $nextPrefix); $visited[$strPrefix] = true; } else { $node['type'] = 'file'; $node['name'] = $item['name']; } $res[] = $node; } return $res; } $tree = buildTree($list); // echo json_encode($list, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); echo json_encode($tree, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT);

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.90.0080.01016.76
8.5.80.0100.01116.70
8.5.70.0090.00616.75
8.5.60.0080.00616.87
8.5.50.0100.00816.66
8.5.30.0120.00717.43
8.5.20.0080.00920.14
8.5.10.0130.00716.72
8.5.00.0160.01020.03
8.4.240.0120.01019.61
8.4.230.0100.01119.73
8.4.220.0050.00419.80
8.4.210.0140.00919.41
8.4.180.0160.00919.67
8.4.170.0110.01120.54
8.4.160.0130.00923.86
8.4.150.0080.00516.85
8.4.140.0160.00717.79
8.4.130.0050.00418.75
8.4.120.0090.01024.14
8.4.110.0150.00618.80
8.4.100.0100.01117.84
8.4.90.0120.00917.84
8.4.80.0090.01117.88
8.4.70.0150.01017.63
8.4.60.0130.01020.58
8.4.50.0100.01017.99
8.4.40.0120.00918.62
8.4.30.0000.01020.51
8.4.20.0130.00717.70
8.4.10.0030.00620.72
8.3.330.0090.01318.56
8.3.320.0130.00718.70
8.3.310.0120.00918.64
8.3.300.0090.01320.82
8.3.290.0090.01120.82
8.3.280.0150.00518.60
8.3.270.0130.00716.52
8.3.260.0110.00916.66
8.3.250.0100.00818.82
8.3.240.0090.01117.18
8.3.230.0090.01116.55
8.3.220.0100.00917.46
8.3.210.0120.00616.52
8.3.200.0080.00717.14
8.3.190.0110.00818.87
8.3.180.0080.00316.54
8.3.170.0180.00020.54
8.3.160.0110.00717.19
8.3.150.0030.01617.30
8.3.140.0000.00816.82
8.3.130.0080.00016.55
8.3.120.0150.00620.90
8.3.110.0030.00616.63
8.3.100.0160.00318.49
8.3.90.0040.00426.77
8.3.80.0030.00619.36
8.3.70.0110.00318.56
8.3.60.0110.00416.75
8.3.50.0090.01123.71
8.3.40.0090.00921.98
8.3.30.0000.01418.83
8.3.20.0040.00424.18
8.3.10.0070.00724.66
8.3.00.0040.00426.16
8.2.320.0090.00818.04
8.2.310.0150.00618.10
8.2.300.0060.00718.23
8.2.290.0070.01220.48
8.2.280.0070.00418.78
8.2.270.0090.00917.27
8.2.260.0040.00416.80
8.2.250.0030.00616.61
8.2.240.0100.01017.02
8.2.230.0080.00020.94
8.2.220.0070.00316.74
8.2.210.0050.00326.77
8.2.200.0090.00018.88
8.2.190.0000.01516.58
8.2.180.0130.00325.92
8.2.170.0000.01418.96
8.2.160.0110.00422.96
8.2.150.0000.00825.66
8.2.140.0060.00324.66
8.2.130.0050.00226.16
8.2.120.0080.00020.57
8.2.110.0090.00019.14
8.2.100.0080.00417.91
8.2.90.0040.00417.63
8.2.80.0100.00018.73
8.2.70.0040.00417.90
8.2.60.0030.00618.20
8.2.50.0050.00318.10
8.2.40.0000.00819.49
8.2.30.0000.00719.22
8.2.20.0000.00718.16
8.2.10.0000.00819.39
8.2.00.0040.00419.35
8.1.340.0090.01217.61
8.1.330.0120.00622.19
8.1.320.0040.00416.34
8.1.310.0000.00816.75
8.1.300.0030.00618.73
8.1.290.0030.00630.84
8.1.280.0070.01125.92
8.1.270.0000.00823.99
8.1.260.0080.00026.35
8.1.250.0070.00028.09
8.1.240.0040.00722.05
8.1.230.0070.00420.97
8.1.220.0000.00818.69
8.1.210.0040.00418.77
8.1.200.0060.00317.35
8.1.190.0000.00917.23
8.1.180.0040.00418.10
8.1.170.0050.00318.26
8.1.160.0070.00018.93
8.1.150.0040.00418.89
8.1.140.0000.00718.97
8.1.130.0000.00720.31
8.1.120.0040.00417.41
8.1.110.0000.00717.46
8.1.100.0070.00017.46
8.1.90.0040.00417.36
8.1.80.0060.00317.44
8.1.70.0000.00717.47
8.1.60.0040.00417.64
8.1.50.0060.00317.49
8.1.40.0040.00417.56
8.1.30.0040.00417.73
8.1.20.0030.00617.67
8.1.10.0040.00417.62
8.1.00.0040.00417.41
8.0.300.0000.00720.01
8.0.290.0040.00416.88
8.0.280.0030.00318.41
8.0.270.0030.00616.83
8.0.260.0030.00320.24
8.0.250.0000.00716.98
8.0.240.0040.00417.00
8.0.230.0070.00016.96
8.0.220.0030.00316.82
8.0.210.0000.00716.91
8.0.200.0020.00516.95
8.0.190.0040.00416.99
8.0.180.0000.00716.90
8.0.170.0030.00616.96
8.0.160.0040.00417.00
8.0.150.0000.00716.90
8.0.140.0080.00016.88
8.0.130.0030.00313.30
8.0.120.0080.00016.87
8.0.110.0040.00417.05
8.0.100.0040.00416.87
8.0.90.0030.00516.86
8.0.80.0070.00916.92
8.0.70.0050.00316.96
8.0.60.0050.00216.84
8.0.50.0030.00616.95
8.0.30.0060.01217.21
8.0.20.0110.01217.12
8.0.10.0050.00317.06
8.0.00.0200.00416.50
7.4.330.0050.00015.55
7.4.320.0030.00316.61
7.4.300.0030.00316.69
7.4.290.0070.00016.50
7.4.280.0000.00816.62
7.4.270.0040.00416.66
7.4.260.0060.00013.35
7.4.250.0070.00016.49
7.4.240.0030.00316.58
7.4.230.0000.00716.64
7.4.220.0020.00516.56
7.4.210.0070.00816.53
7.4.200.0000.00716.62
7.4.130.0130.00716.62
7.4.120.0160.00616.50
7.4.110.0090.00816.27
7.4.100.0110.00616.31
7.4.90.0080.01016.41
7.4.80.0110.00716.29
7.4.70.0070.01016.25
7.4.60.0090.01016.26
7.4.50.0140.00616.31
7.4.40.0100.00716.38
7.4.30.0100.00716.36
7.4.20.0060.01116.23
7.4.10.0110.00716.41
7.4.00.0140.00316.46
7.3.330.0040.00416.41
7.3.320.0000.00513.41
7.3.310.0030.00316.31
7.3.300.0000.00716.38
7.3.290.0110.00716.43
7.3.260.0190.00316.39
7.3.230.0110.00616.38
7.3.220.0060.01016.22
7.3.210.0030.01416.40
7.3.200.0080.01016.13
7.3.190.0130.00516.36
7.3.180.0110.00916.42
7.3.170.0110.00716.43
7.3.160.0050.01316.58
7.3.150.0070.00916.30
7.3.140.0120.00416.46
7.3.130.0110.00516.51
7.3.120.0130.00716.25
7.3.110.0100.00616.36
7.3.100.0120.01116.42
7.3.90.0090.01016.50
7.3.80.0070.01016.40
7.3.70.0090.00716.30
7.3.60.0130.00616.36
7.3.50.0120.00416.37
7.3.40.0110.00716.45
7.3.30.0080.00816.55
7.3.20.0120.00616.46
7.3.10.0180.01016.46
7.3.00.0100.00716.44
7.2.340.0110.00716.75
7.2.330.0110.00816.42
7.2.320.0090.01016.37
7.2.310.0120.01416.47
7.2.300.0130.00516.45
7.2.290.0050.01416.66
7.2.280.0110.00716.54
7.2.270.0120.00716.64
7.2.260.0070.01016.69
7.2.250.0080.00916.73
7.2.240.0140.01016.59
7.2.230.0090.00916.50
7.2.220.0090.01016.27
7.2.210.0080.00916.60
7.2.200.0080.00816.54
7.2.190.0100.00816.64
7.2.180.0100.00716.65
7.2.170.0150.00416.64
7.2.160.0050.01316.60
7.2.150.0190.00816.59
7.2.140.0070.01216.67
7.2.130.0160.00316.61
7.2.120.0070.01016.53
7.2.110.0110.00616.65
7.2.100.0090.00816.66
7.2.90.0050.01516.66
7.2.80.0090.00916.70
7.2.70.0050.01316.67
7.2.60.0100.00816.66
7.2.50.0070.01216.61
7.2.40.0120.00716.71
7.2.30.0110.00816.78
7.2.20.0110.00816.55
7.2.10.0080.01116.60
7.2.00.0090.00916.62

preferences:
49.33 ms | 2529 KiB | 5 Q