Jump to content

Array Sort *SOLVED*


DannyTip

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
...[/code]

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.
Link to comment
Share on other sites

Having sorted the array you can use
[code]
foreach ($array as $image) {
        echo $image . '<br />';
}
[/code]

to process them in order.

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

which will give
[pre][nobbc]
[0] => DSC00346.jpg
[1] => DSC00347.jpg
[2] => DSC00351.jpg
....
[/nobbc]
[/pre]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.