Page 1 of 1

arrays

Posted: Sat Jan 08, 2005 11:58 pm
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?

Posted: Sun Jan 09, 2005 12:00 am
by John Cartwright
show us code.

Posted: Sun Jan 09, 2005 12:01 am
by feyd
*thinks to himself, rather loudly* this thread is useless without code. :P

Posted: Sun Jan 09, 2005 12:07 am
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 :)

Posted: Sun Jan 09, 2005 12:11 am
by feyd

Code: Select all

$foo = array();

Code: Select all

$foo&#1111;] = $readdir;

Code: Select all

sort($foo);
print_r($foo);