Re: sorting readdir output? [message #184005 is a reply to message #184004] |
Sun, 01 December 2013 18:19 |
Lew Pitcher
Messages: 60 Registered: April 2013
Karma:
|
Member |
|
|
On Sunday 01 December 2013 13:10, in comp.lang.php, "richard"
<noreply(at)example(dot)com> wrote:
> On Sun, 01 Dec 2013 18:32:59 +0100, Luuk wrote:
>
>> On 01-12-2013 17:39, richard wrote:
>>> <?php
>>>
>>> if ($handle = opendir('../audio/1960/')) {
>>> echo "Directory handle: $handle\n";
>>> echo "Entries:\n";
>>>
>>> /* This is the correct way to loop over the directory. */
>>> while (false !== ($entry = readdir($handle))) {
>>> echo "$entry\n<br>";
>>> }
>>>
>>> closedir($handle);
>>> }
>>> ?>
>>>
>>> This gives the output in an unsorted list.
>>> How can I make it so the array is sorted?
>>
>>
>> which array?
>> http://us2.php.net/manual/en/language.types.array.php
>>
>> but if you DO have an array, dan sorting is easy:
>> http://us2.php.net/manual/en/function.sort.php
>>
>>>
>>> http://us1.php.net/readdir
>>>
>>
>> yep, it's all in the manual....
>
> The array is created from $handle I believe.
You believe wrong.
opendir() returns a "handle", which is a "resource", and a "resource" is "a
special variable, holding a reference to an external resource."
The handle returned by opendir(), that is used in readdir() and closedir()
is NOT an array or list of directory entries.
--
Lew Pitcher
"In Skills, We Trust"
PGP public key available upon request
|
|
|