You wonder how to reverse a String without using a Built in Function strrev() in PHP?.
This question asked many times in Interviews.
I got a solution here.
Just see the below lines of codes.
<?php $str = "SPIDERMAN"; $len = strlen($str); for($i=$len-1; $i>=0; $i--) { echo $str[$i]; } ?>
First calculate the string length using the “strlen()” function.
After finding the length just loop through the string and print one by one.
Do you know how to reverse a string not using any Loops or any Built in function like “strlen()”?.
Get the solution here CLICK HERE
program to reverse a string in php without using string functions in this program you are using strlen , i dont want to use this , is there any way to find string length by using
array concepts
$string = ‘RAVINDRA’;
$i = 0;
while(isset($string[$i])){
$i++;
}
$i–;
while(isset($string[$i])){
echo $string[$i];
$i–;
}
String index can help us.
$string = ‘RAVINDRA’;
$i = 0;
while(isset($string[$i])){
$i++;
}
$i–;
while(isset($string[$i])){
echo $string[$i];
$i–;
}
Thanks!. Awesome work!
$string = ‘HIREN’;
$i = 0;
while(isset($string[$i])){
$i++;
}
$i–; // must be —
while(isset($string[$i])){
echo $string[$i];
$i–; // must be —
}