Tag Archives: reverse

Reverse order of individual items in a delimited string

Topic: Reversing the order of individual items in a string. Specifics: I had a date contained in a GET query string that was formatted as follows: 01/27/2013 and I needed it reversed to 2013/01/27 Here is a simple method to do the reversing in PHP: $toDate = htmlentities($_GET[‘to’]); $toDateNew = implode(“/”,(array_reverse(explode(“/”,$toDate)))); Explanation of code: First you explode the $toDate variable, then reverse the resulting array, finally you implode that array back into a string. Of course there are other date