3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function dirToArray1($dir) { $result = array(); $cdir = scandir($dir); foreach ($cdir as $key => $value) { if (!in_array($value,array(".",".."))) { if (is_dir($dir . DIRECTORY_SEPARATOR . $value)){ $result[$value] = dirToArray1($dir . DIRECTORY_SEPARATOR . $value); } else { $result[] = $value; } } } return $result; } function dirToArray2($dir) { $arr = []; $obj = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir), RecursiveIteratorIterator::CHILD_FIRST); foreach ($obj as $info) { if (in_array($info->getFilename(), ['.', '..'])) continue; $path = $info->isDir() ? [$info->getFilename() => []] : [$info->getFilename()]; for ($depth = $obj->getDepth() - 1; $depth >= 0; $depth--) { $path = [$obj->getSubIterator($depth)->current()->getFilename() => $path]; } $arr = array_merge_recursive($arr, $path); } return $arr; } foreach (['1', '2'] as $k) { $t = "t$k"; $d = "d$k"; $$t = microtime(true); $func = "dirToArray$k"; $$d = $func("/"); $$t = microtime(true) - $$t; echo "$func needed " . $$t . " time\n"; }

Abusive script

This script was stopped while abusing our resources

Output for 5.4.0 - 5.4.17
Warning: scandir(//etc): failed to open dir: Permission denied in /in/f9ra2 on line 5 Warning: scandir(): (errno 13): Permission denied in /in/f9ra2 on line 5 Warning: Invalid argument supplied for foreach() in /in/f9ra2 on line 6 Warning: scandir(//in): failed to open dir: Permission denied in /in/f9ra2 on line 5 Warning: scandir(): (errno 13): Permission denied in /in/f9ra2 on line 5 Warning: Invalid argument supplied for foreach() in /in/f9ra2 on line 6 Warning: scandir(//proc): failed to open dir: Permission denied in /in/f9ra2 on line 5 Warning: scandir(): (errno 13): Permission denied in /in/f9ra2 on line 5 Warning: Invalid argument supplied for foreach() in /in/f9ra2 on line 6 Warning: scandir(//root): failed to open dir: Permission denied in /in/f9ra2 on line 5 Warning: scandir(): (errno 13): Permission denied in /in/f9ra2 on line 5 Warning: Invalid argument supplied for foreach() in /in/f9ra2 on line 6 Warning: scandir(//run): failed to open dir: Permission denied in /in/f9ra2 on line 5 Warning: scandir(): (errno 13): Permission denied in /in/f9ra2 on line 5 Warning: Invalid argument supplied for foreach() in /in/f9ra2 on line 6
Process exited with code 137.
Output for 5.2.15 - 5.3.27
Parse error: syntax error, unexpected '[' in /in/f9ra2 on line 19
Process exited with code 255.