Jump to content


This topic is now archived and is closed to further replies.


Array Sort *SOLVED*

Recommended Posts

Im using natcasesort() to sort an array of image files.  This works great but i want a method of skipping to the next/previous image file.  But the problem is that when the array is sorted it doesnt reset the internal pointer i.e.

[code][0] => DSC00346.jpg
[42] => DSC00347.jpg
[47] => DSC00351.jpg
[40] => DSC00353.jpg
[6] => DSC00354.jpg
[7] => DSC00355.jpg
[36] => DSC00356.jpg

I know i could use key() to get the pointer for say 'DSC00354.jpg' but is there anyway to get the one for the record after? Or simply reset the pointers so they are still in order.

Share this post

Link to post
Share on other sites
Having sorted the array you can use
foreach ($array as $image) {
        echo $image . '<br />';

to process them in order.

If you want the indexes reset to 0, 1, 2
$array = array_values($array);[/code]

which will give
[0] => DSC00346.jpg
[1] => DSC00347.jpg
[2] => DSC00351.jpg

Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.