I'm not sure if $array is an acceptable variable name. That might be one of your problems.
But your main problem is that your assignment of the array is incorrect. I think you want something like:
while ($file = readdir($dir))
{
$my_array[] = $file;
}
The keys of this array will be simple index numbers. The values will be the contents of $file.
FWIW, it doesn't seem like it makes much sense to create an array where the key has the same data as the value.
You might also try look at the PHP manual for a description / example for how to use list() and each(). I think it contains an example of how to grab the keys and values of each element of an array.
Something like:
while (list($key,$value) = each($my_array))
{
echo("The key is $key.");
echo("The value is $value.");
}