php images sorting by reserve

I have the following code:


Header(“content-type: application/x-javascript”);


$locationstring=“http://” . $_SERVER[‘HTTP_HOST’].$pathstring[‘dirname’] . “/”;

function returnimages($dirname=".") {


$files = array();


if($handle = opendir($dirname)) {

   while(false !== ($file = readdir($handle))){

           if(eregi($pattern, $file)){

                 echo 'picsarray[' . $mostRecent .']="' . $file . '";';








echo ‘var locationstring="’ . $locationstring . ‘";’;

echo ‘var picsarray=new Array();’;


?> [/php]

I want to sort the images by reverse because This code sort pictures like this: picsarray[0]=“2013-11-29 11:42:11 pm.jpg”;picsarray[1]=“2013-11-29 11:58:24 pm.jpg”;picsarray[2]=“2013-11-30 12:13:36 am.jpg”;picsarray[3]=“2013-11-30 12:27:46 am.jpg”

I want to sort them by reverse. Anyone can help me to fix this problem?

If you don’t want to write the logic to reverse the array, you can simply use the built in PHP Function


You can read about it here and view the examples.

Sponsor our Newsletter | Privacy Policy | Terms of Service