# Sorting arrays in php - then back to Flash

**URL:** <https://forum.kirupa.com/t/sorting-arrays-in-php-then-back-to-flash/131809>\
**Category:** Uncategorized\
**Created:** [December 20, 2004, 4:36am UTC](https://forum.kirupa.com/t/sorting-arrays-in-php-then-back-to-flash/131809 "2004-12-20T04:36:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![vman](https://avatars.discourse-cdn.com/v4/letter/v/5e9695/32.png) [@vman](https://forum.kirupa.com/u/vman)\
**Post date:** [December 20, 2004, 4:36am UTC](https://forum.kirupa.com/t/sorting-arrays-in-php-then-back-to-flash/131809/1 "2004-12-20T04:36:04Z")

</div>

Hello everyone. I have a problem that I can’t seem to solve. I have a completely dynamic imageviewer that creates a specific number of buttons based on how many folders are in a directory. I have php script that does this. I can’t figure out how to arrange the array in alphabetical order before it is sent back to Flash. I ahve also tried sorting in Flash and have been unsuccessful. Here’s is the script I have so far which is way off I know. Can someone give me a hand with this? Thanks.

```php
<?
$dir = "Gigs";
$dh = opendir($dir);
while (false !== ($filename = readdir($dh))) {
if($filename != "." && $filename != "..") {
$foldernames=array($filename);

}
}
closedir($dh);

sort($foldernames);

foreach($foldernames as $val) {
 echo "&foldernames=".$val;
 
}
?>

```

Here’s a link to the image viewer:  
[http://thezplane.com/Imageviewer/](http://thezplane.com/Imageviewer/)
