PHP | strrev() Function
Reversing a string is one of the most basic string operations and is used very frequently by developers and programmers. PHP comes with a built-in function to reverse strings.
The strrev() function is a built-in function in PHP and is used to reverse a string. This function does not make any change in the original string passed to it as a parameter.
Synatx:
string strrev($inpString)
Parameter: This function accepts a single parameter $inpString. This parameter is a string and it specifies the string which we want to reverse. If a number is passed to it instead of a string, it will also reverse that number.
Return Value: The strrev() function returns the reversed string or the number. It does not make any change to the original string or number passed in the parameter.
Examples:
Input : $string = "geeks" Output : skeeg Input : $string = 143 Output : 341
Below programs illustrate the strrev() function in PHP:
Program 1: PHP program to demonstrate the strrev() function when a string is passed.
<?php // PHP program to demonstrate the // strrev() function when a string is passed $str = "geeks"; // prints the reversed string echo strrev($str); ?> |
Output:
skeeg
Program 2: PHP program to demonstrate the strrev() function when a number is passed.
<?php // PHP program to demonstrate the // strrev() function when a number is passed // passing number instead of string $num = 134; // prints the reversed number echo strrev($num); ?> |
Output:
431
Reference:
http://php.net/manual/en/function.strrev.php
Recommended Posts:
- How to call a function that return another function in JavaScript ?
- How to get the function name from within that function using JavaScript ?
- p5.js | min() function
- p5.js | cos() function
- p5.js | log() function
- p5.js | max() function
- PHP | exp() Function
- PHP | tan( ) Function
- p5.js | red() function
- PHP | next() Function
- p5.js | sin() function
- PHP Ds\Set get() Function
- PHP Ds\Set sum() Function
- PHP | pow( ) Function
- p5.js | pow() function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



