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!
Hi, I'm trying to use sort to alphabetize a listing of names but I'm having trouble with the functions. I need to open the list, read it into an array, sort it and then rewrite the list in alphabetic order. Here's what I have but it isn't working as expected.
Mark, thanks, that stops the errors. However, now the output back to the file after being sorted isn't the directory listing in alphabetic order, but rather just the word "Array"?
//Alpha sort the directory
$fpp = fopen("listing.php", 'r');
$x = 0;
while(!feof($fpp)) {
$line[$x] = fgets($fpp, 1024);
$x++;
}
fclose($fpp);
sort($line);
reset($line);
// Rewrite the directory
$ffpp = fopen("listing.php", 'w');
foreach($line as $new_line) { // itterate through the array and write each line
fwrite($ffpp, "$new_line\n"); // write the line and insert a line break
}
fclose($ffpp);