3v4l.org

run code in 300+ PHP versions simultaneously
<?php $folders = array( 'test/something.txt', 'test/hello.txt', 'test/another-folder/myfile.txt', 'test/another-folder/kamil.txt', 'test/another-folder/john/hi.txt' ); $newFolders = array(); foreach ($folders as $file) { $parts = explode("/", $file); if (array_key_exists($parts[0], $parts)) { $newFolders = array( $parts[0][] => $parts[1] ); } else { $newFolders = array( $parts[0] => $parts[1] ); } } print_r($newFolders);
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.27
Fatal error: Cannot use [] for reading in /in/8IL5a on line 17
Process exited with code 255.

preferences:
190.37 ms | 1399 KiB | 64 Q