• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

Some PHP help, por favor?

Injury

Lifer
Wrote some code to help me display some image galleries on my site... but I want them to display in alpahbetical order... so that I don't have rename files and the "img_32452435" will sort them.

They currently display in REVERSE order. How can change this?

Also... I'm new to coding from scratch. Any tips or suggestions for the code would rock. 🙂
 
I don't know any PHP, so while one could reasonably expect the language to have a reverse sorting function (google seems to suggest arsort instead of asort), try changing this:

for($t = 0; $t < $numberOfFiles; $t++)

to this

for($t = $numberOfFiles - 1; $t >= 0 ; $t--)
 
Originally posted by: Neverm1nd
I don't know any PHP, so while one could reasonably expect the language to have a reverse sorting function (google seems to suggest arsort instead of asort), try changing this:

for($t = 0; $t < $numberOfFiles; $t++)

to this

for($t = $numberOfFiles - 1; $t >= 0 ; $t--)

No dice 🙁

Still sorts in reverse alpha

any combo of the code you gave and the asort/arsort doesn't change anything.

Thanks, though. 🙂
 
Assuming readdir scans the files alphabetically, try taking the asort call out and see how it sorts. If that doesn't work, try calling asort twice
 
asort sorts the values of an array, you're using the file names as the key, try ksort instead of asort to sort on the key instead of the value.
 
Originally posted by: hg403
Assuming readdir scans the files alphabetically, try taking the asort call out and see how it sorts.

That worked!

Thanks bunches for the help guys.

My next project to help me learn php: A ransom note generator! 😉 hahaha.
 
Back
Top