Reverse the string to get out as This is durga @ no. 1 position. Is below solution memory optimistic. How can we achieve the same without using a string function like i used strlen.
<?php
$string = "position 1 no. @ durga is This";
$reversed = "";
$tmp = "";
for ($i = 0; $i < strlen($string); $i++) {
if ($string[$i] == " ") {
$reversed .= $tmp . " ";
$tmp = "";
continue;
}
$tmp = $string[$i] . $tmp;
}
$reversed .= $tmp;
print strrev($reversed) . PHP_EOL;