Hackerss.com is a community of amazing hackers

Hackerss is a community for developers, data scientitst, ethical hackers, hardware enthusiasts or any person that want to learn / share their knowledge of any aspect of digital technology.

Create account Log in

Posted on

Reverse a string in Php

Reverse a string - Php:

function reverseString($string) {
  $reversed = '';
  // loop through the string backwards
  for ($i = strlen($string) - 1; $i >= 0; $i--) {
    // append each character to the reversed string
    $reversed .= $string[$i];
  // return the reversed string
  return $reversed;

$result = reverseString('hello');

echo $result; //olleh
Enter fullscreen mode Exit fullscreen mode

Top comments (0)