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? 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; ?> 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! Link to comment https://forums.phpfreaks.com/topic/161563-solved-reverse-string-bits/#findComment-852581 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.