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
https://forums.phpfreaks.com/topic/24582-array-sort-solved/
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
https://forums.phpfreaks.com/topic/24582-array-sort-solved/#findComment-112014
Share on other sites

Archived

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

×
×
  • 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.