Contact US


Get Your Project Done by our experts
info@fundaofwebit.com

How to reverse a string in php without using predefined function

Whatsapp

https://www.fundaofwebit.com/post/how-to-reverse-a-string-in-php-without-using-predefined-function

How to reverse a string in php without using predefined function.


Here, in this post, let's begin with reversing a string in php where we are not using any default or predefined function of php like, strrev() and strlen().


<?php

$string = "ved";

$string_lenght = 0;

while($string[$string_lenght] != null){
$string_lenght++;
}
$string_lenght; //Total String Lenght

//$string_lenght = strlen($string);

for ($i=($string_lenght-1); $i >= 0; $i--)
{
echo "Reversed String : ". $string[$i];
}

?>


Output: 

Reversed String : dev


Thanks for reading.

© Copyright - 2018 - 2021 | All rights reserved at Funda of Web IT