Image Gallery - how to sort images. [SOLVED]

Post here is you are having problems with any of the tutorials.
Post Reply
User avatar
rabatos
Posts: 46
Joined: Thu Aug 09, 2012 11:06 am

Image Gallery - how to sort images. [SOLVED]

Post by rabatos »

Following the Automatic Image Gallery System.

Is there a way to display the images in a certain order.

Basically I want to have the images displayed in the order of the most recently added image.

So date order.

I have a file upload function, which I can use to add new photos to the gallery,

hence why I'd like to display new images first.

If anyone can help, thanks
User avatar
rabatos
Posts: 46
Joined: Thu Aug 09, 2012 11:06 am

Re: Image Gallery - how to sort images. [SOLVED]

Post by rabatos »

I've found the solution.

[syntax=php]
$images = glob("*.{jpg,jpeg,png,gif}", GLOB_BRACE);

array_multisort(
array_map( 'filemtime', $images ),
SORT_NUMERIC,
SORT_DESC,
$images
);
[/syntax]

The array_multisort() function is explained here:
http://www.w3schools.com/php/func_array_multisort.asp
User avatar
jacek
Site Admin
Posts: 3262
Joined: Thu May 05, 2011 1:45 pm
Location: UK
Contact:

Re: Image Gallery - how to sort images. [SOLVED]

Post by jacek »

I just learnt something :P

I was going to suggest a usort() but that way looks much nicer,
Image
User avatar
rabatos
Posts: 46
Joined: Thu Aug 09, 2012 11:06 am

Re: Image Gallery - how to sort images. [SOLVED]

Post by rabatos »

haha, you're welcome.
Post Reply