The [man]readdir[/man] manual page contains an example of a script that lists the contents of a directory (Example 1).
To modify that to produce an array instead of just echoing what it finds,
put a line
$directory_listing = array();
just before the first line of that example, and replace the echo line with
$directory_listing[] = $file;
Remember to read the comments in that example; your code should only have the one while() loop!