Re: Sorting Arrays
| From: | Jay Greenspan | Date: | Sat, 19 Aug 2000 00:22:11 +0000 |
| Subject: | Re: Sorting Arrays | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-12551@lists.php.net to get a copy of this message | ||
You need to create the array before you can sort it.
Something like this should work, I think.
$d = dir("/your/path");
while($artist_list=$d->read())
{
if(is_dir("path/$artist_list"))
{
$artist[] = $artist_list;
}
}
sort($artist);
foreach($artist as $value)
{
echo "$value<BR>\n";
}
$d->close();
?>
-----Original Message-----
From: "Phillip S. Baker" <phillip@wordsandimages.com>
Newsgroups: php.general
Date: Friday, August 18, 2000 3:25 PM
Subject: [PHP] Sorting Arrays
>Greetings All,
>
>Here is the code
>
>
>$d = dir("jukebox/");
>while($artist_list=$d->read())
>{
> if(is_dir("/music/jukebox/$artist_list"))
> {
> $artist = array($artist_list);
> $artist = implode($artist, "<BR>");
> sort($artist);
> if ($artist != "." && $artist != "..")
> {
> echo "$artist<BR>\n";
> }
> }
>}
>$d->close();
>
>Now what I am trying to do here is to get a listing of all the
>directories in the folder jukebox. Now I want this list that pulls up
>to be sorted in alpahbetical order.
>Right now
>I want to plug these folders into the variable $artist_list. This
>variable in turn goes into the array $artist. I then I am trying to
>sort the variable $artist.
>
>What I get is an error that says wrong datatype in sort.
>The array does display (which this error next to each echo) but it is
>not sorted.
>
>How do I fix this?
>How do I sort the array like I want to?
>
>Thanks
>--
>
>Phillip S. Baker
>
>phillip@wordsandimages.com
>Words & Images, Inc.
>1535 Seabright Avenue, Suite 100, Santa Cruz, CA 95062
>Direct Line (831) 420-2641 / Fax (831) 458-0808
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
>For additional commands, e-mail: php-general-help@lists.php.net
>To contact the list administrators, e-mail: php-list-admin@lists.php.net
>