AtomicRax Posted June 9, 2009 Share Posted June 9, 2009 I'm trying to reverse a string, but I don't want it completely backwards... I have: $str = "10,8,6,4,2"; It is not an array, and can't be an array. It's simply a string with commas. I want to reverse it so it says "2,4,6,8,10". BUT, if I do a regular string reverse, it'll say "2,4,6,8,01" That's not what I'm looking for... How can I do this? Quote Link to comment https://forums.phpfreaks.com/topic/161563-solved-reverse-string-bits/ Share on other sites More sharing options...
Maq Posted June 9, 2009 Share Posted June 9, 2009 Maybe there's an easier way but you can explode it with a comma delimiter, reverse the the array, and implode it back together. $str = "10,8,6,4,2"; $p = explode(",",$str); $str = implode(",",array_reverse($p)); echo $str; ?> Quote Link to comment https://forums.phpfreaks.com/topic/161563-solved-reverse-string-bits/#findComment-852575 Share on other sites More sharing options...
AtomicRax Posted June 9, 2009 Author Share Posted June 9, 2009 Thanks, that worked just fine for me! Quote Link to comment https://forums.phpfreaks.com/topic/161563-solved-reverse-string-bits/#findComment-852581 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.