mpsn Posted November 6, 2011 Share Posted November 6, 2011 Hi, when I output this, it's same order, I want it to be: email/message/to/toLastName please see code: $testArray=array("toLastName","to","message","email"); $reversedTestArray=rsort($testArray);//rsort returns TRUE on success //$strTestArrayReversed=implode(",",$testArray); print_r($testArray); Any idea what I am doingwrong, it looks fairly straightforward. Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/250541-why-doesnt-rsort-work/ Share on other sites More sharing options...
mpsn Posted November 6, 2011 Author Share Posted November 6, 2011 It just print: 1... Doesn't that just mean TRUE? Quote Link to comment https://forums.phpfreaks.com/topic/250541-why-doesnt-rsort-work/#findComment-1285406 Share on other sites More sharing options...
Pikachu2000 Posted November 6, 2011 Share Posted November 6, 2011 As it says in the comments in your code, rsort returns true on success. It doesn't return an array. See the examples in the manual. Quote Link to comment https://forums.phpfreaks.com/topic/250541-why-doesnt-rsort-work/#findComment-1285410 Share on other sites More sharing options...
mpsn Posted November 6, 2011 Author Share Posted November 6, 2011 Ok, I don't know how to use rsort, so I used array_reverse: $testArray=array("toLastName","to","message","email"); $reversedTestArray=array_reverse($testArray);//rsort returns TRUE on success $strTestArrayReversed=implode(",",$reversedTestArray); print $strTestArrayReversed; Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/250541-why-doesnt-rsort-work/#findComment-1285411 Share on other sites More sharing options...
xyph Posted November 6, 2011 Share Posted November 6, 2011 array_reverse and rsort do different things. Your original array was already in reverse alphabetical order, so applying rsort to it does nothing. Quote Link to comment https://forums.phpfreaks.com/topic/250541-why-doesnt-rsort-work/#findComment-1285587 Share on other sites More sharing options...
jcbones Posted November 6, 2011 Share Posted November 6, 2011 to get the results you specified in the original post, you just use sort(). <?php $testArray=array("toLastName","to","message","email"); sort($testArray); echo implode('/',$testArray); ?> Quote Link to comment https://forums.phpfreaks.com/topic/250541-why-doesnt-rsort-work/#findComment-1285660 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.