Re: Sorting Arrays

From: Date: Mon, 21 Aug 2000 21:11:18 +0000
Subject: Re: Sorting Arrays
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-12812@lists.php.net to get a copy of this message
On Mon, 21 Aug 2000, Phillip S. Baker wrote: > 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 is an array here. > $artist = implode($artist, "<BR>"); Now you've made $artist a string with the 'implode' function. $artist is now each string in array($artist_list) separated by "<BR>". > sort($artist); You're trying to sort a string; can't do it. > if ($artist != "." && $artist != "..") > { > echo "$artist<BR>\n"; > } > } > } > $d->close(); > You should sort the array before you implode it and then iterate through it instead of using a simple "if" statement. > 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? > And I want to do this in PHP3. > > Thanks >

« previous php.general (#12812) next »