<?php function readDirctory($path) { if (!is_dir($path)) { return false; } $handle = opendir($path); $arr = []; while ( ($file = readdir($handle)) !== false ) { if ($file != '.' && $file != '..') { if (is_file($path . '/' . $file)) { $arr['file'][] = $file; } if (is_dir($path . '/' . $file)) { $arr['dir'][] = $file; } } } closedir($handle); return $arr; } $path = "abc"; $res = readDirctory($path); print_r($res);