arrays

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

arrays

Post by shiznatix »

ok this is really stupid but im sorry i cant figure it out or find it on google. im trying to open a directory then make a array out of the files in the directory then sort them into alphabetical order. i used readdir, then array (and tried file), then sort, then print the sorted array but the only result i could get was the number 1. help?
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

show us code.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

*thinks to himself, rather loudly* this thread is useless without code. :P
User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post by shiznatix »

lol sorry saviours of mine,

Code: Select all

<?php
$dir = "users/" . $_SESSION['encrypt'] . "/diskdriver/beta";//point to the directory of the user
$opendir = opendir($dir);//open the dir
print "<a href='users/" . $_SESSION['encrypt'] . "/diskdriver.swf' target='_blank'>Play My Music!</a><br><br>";
	while (false !== ($readdir = readdir($opendir))){
		if ($readdir != "." && $readdir != ".."){
		$readdir = str_replace(".mp3", "", $readdir);
		print "$readdir";//print out the names of each file in the directory
		}
	}
?>
but i want the files to be displayed in alphabetical order. hook a brotha up :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Code: Select all

$foo = array();

Code: Select all

$foo&#1111;] = $readdir;

Code: Select all

sort($foo);
print_r($foo);
Post Reply