3v4l.org

run code in 300+ PHP versions simultaneously
<?php echo getcwd();exit; 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("/tmp"); $$t = $$t - microtime(true); echo "$func needed $$t time\n"; }
Output for 5.4.0 - 5.4.45, 5.5.0 - 5.5.38, 5.6.0 - 5.6.40, 7.0.0 - 7.0.33, 7.1.0 - 7.1.33, 7.2.0 - 7.2.34, 7.3.0 - 7.3.31, 7.4.0 - 7.4.25, 8.0.0 - 8.0.12
/
Output for 5.2.3 - 5.2.17, 5.3.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/VQAE4 on line 21
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.1.6, 5.2.0 - 5.2.2
<br /> <b>Parse error</b>: syntax error, unexpected '[' in <b>/in/VQAE4</b> on line <b>21</b><br />
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.3.11, 4.4.0 - 4.4.1, 5.0.0 - 5.0.5
<br /> <b>Parse error</b>: parse error, unexpected '[' in <b>/in/VQAE4</b> on line <b>21</b><br />
Process exited with code 255.
Output for 4.3.2 - 4.3.4
<br /> <b>Parse error</b>: parse error in <b>/in/VQAE4</b> on line <b>21</b><br />
Process exited with code 255.

preferences:
299.74 ms | 401 KiB | 386 Q