Simple image sorting

I need help modifying the following code.

I would like it to display the latest 15 images in random order.

Currently it shows then in reverse chronological.

Can someone help me?

[php]<?php

//Your folder

$files = glob(“images/.”);

function sortnewestfilesfirst($a, $b) {

return filemtime($b) - filemtime($a);

}

usort($files, “sortnewestfilesfirst”);

$colCnt=0;

echo ‘

’;

for ($i=0;$i<15;$i++)

{

$colCnt++;

if ($colCnt==1)

echo ‘

’;

echo ‘

’;

if ($colCnt==2)

{

echo '</tr>';

$colCnt=0;

}

}

echo ‘

’;

$num = $files[$i];

echo ’

<div class="clipin"> <a href="' . $num . '" rel="lightbox[all]"><img class="thumb ImgBorder" src="'.$num.'">  

'."  ";

echo ‘

’;

?>[/php]

Use this on your array:
[php]
shuffle($files);
[/php]

That should randomly sort the $files array everytime.

Thanks this worked to shuffle them. But how do I only shuffle the last 15?

[php]
$output = array_slice($files, -15, 15);
shuffle($output);
[/php]

Use $output as your new array which should now hold only the latest 15 elements and shuffled…

Sponsor our Newsletter | Privacy Policy | Terms of Service