How to Reverse Word in a String Using PHP?

Problem:- How to Reverse Word in a String Using PHP?

Solution

There are to Method to reverse a string

Method 1

To reverse every Word

<?php
$string = "Hindi Alerts";
$words = explode(' ', $string);
$words = array_reverse($words);
$string = implode(' ', $words);
echo $string;
?>

Method 2

To reverse every character

<?php
$string = "Hindi Alerts";
$rev_string = strrev($string);
echo $rev_string;
?>

 

Be the first to comment

Leave a Reply

Your email address will not be published.


*