DannyTip Posted October 20, 2006 Share Posted October 20, 2006 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. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 20, 2006 Share Posted October 20, 2006 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, 2use [code]$array = array_values($array);[/code]which will give[pre][nobbc][0] => DSC00346.jpg [1] => DSC00347.jpg [2] => DSC00351.jpg ....[/nobbc][/pre] Quote Link to comment Share on other sites More sharing options...
DannyTip Posted October 20, 2006 Author Share Posted October 20, 2006 Thankyou[code]$array = array_values($array);[/code]is exactly what i needed :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.