Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSam Gord
14,084 Pointsasort / arsort
it seems that i cant get the difference between using asort/arsort in associative arrays and indexed arrays , no matter how many times i replay this video! can anyone please help? thank you in advance ;)
2 Answers
Jason Anders
Treehouse Moderator 145,860 PointsHey Sam,
It just depends on whether you want the results to be sorted in Ascending
or Descending
order. Just remember the the "r" in arsort()
stands for "Reverse"... so, it sorts in reverse order.
asort()
sorts in Ascending
arsort()
sorts in Descending
For example: (2, 6, 1, 7, 4, 3)
asort() will return 1, 2, 3, 4, 6, 7
arsort() wil return 7, 6, 4, 3, 2, 1
Hope that helps! :)
Emil Pesaxov
3,684 PointsSo what is the difference between arsort() and rsort()?
Sam Gord
14,084 PointsSam Gord
14,084 Pointsthanks very much