If you ever wondered how to reversing a string using PHP reverse function “strrev()” and write your own function doing the same thing? Oddly I was asked to write my own PHP function to reverse a string and I though to sharing it.
<?php
//PHP strrev() Function
echo strrev('Hello World'); //dlroW olleH
//My way of doing it
function array_reversed ($array)
{
$array = array_reverse($array);
ksort($array);
return ($array);
}
function my_reverse ($str = null)
{
$data = str_split($str);
$str = array_reversed($data);
return join($str);
}
echo my_reverse("Hello World"); //dlroW olleH
?>