3v4l.org

run code in 300+ PHP versions simultaneously
<?php $directoryTree = [ 'accounting' => [ 'documents' => [ ], 'losses' => [ ], 'profit' => [ ] ], 'legal' => [ 'documents' => [ ] ] ]; $fileList = [ [ 'name' => 'Overview.doc', 'dir_path' => [] ], [ 'name' => 'Incorporation.doc', 'dir_path' => [] ], [ 'name' => 'Profit And Loss.xls', 'dir_path' => ['accounting'] ], [ 'name' => 'Profit 1.xls', 'dir_path' => ['accounting', 'profit'] ], [ 'name' => 'Loss 1.xls', 'dir_path' => ['accounting', 'losses'] ], [ 'name' => 'TOS Draft.doc', 'dir_path' => ['legal', 'documents'] ], [ 'name' => 'Accounting Doc.pdf', 'dir_path' => ['accounting', 'documents'] ], ]; function addFiles2DirectoryTree(array $files, array $directoryTree){ foreach($files as $file) assignFileToPath($file["name"], $file["dir_path"], $directoryTree); return $directoryTree; } function assignFileToPath($filename, $path, &$directoryTree){ while($key = array_shift($path)) $directoryTree = &$directoryTree[$key]; $directoryTree[] = $filename; } $finalOutput = addFiles2DirectoryTree($fileList, $directoryTree); print_r($finalOutput);
Output for git.master, git.master_jit, rfc.property-hooks
Array ( [accounting] => Array ( [documents] => Array ( [0] => Accounting Doc.pdf ) [losses] => Array ( [0] => Loss 1.xls ) [profit] => Array ( [0] => Profit 1.xls ) [0] => Profit And Loss.xls ) [legal] => Array ( [documents] => Array ( [0] => TOS Draft.doc ) ) [0] => Overview.doc [1] => Incorporation.doc )

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
52.52 ms | 402 KiB | 8 Q