Reverse String Program In PHP


Copy Fullscreen Close Fullscreen
<?php
  function reverse_str($str)
  {
    /*get string length*/
    $length = strlen($str);
    for($i=($length -1); $i >= 0; $i--)
    {
      echo $str[$i];
    }
  }

  /*now test*/
  reverse_str('elephant');
  echo '<br>';
  reverse_str('mohit');
?>
Output
tnahpele
tihom

Hey ! I'm Rahul founder of learnhindituts.com. Working in IT industry more than 5.5 years. I love to talk about programming as well as writing technical tutorials and blogs that can help to others .... keep learning :)

Get connected with me - LinkedIn Twitter Instagram Facebook