Reversing a string by word : array_reverse « Data Structure « PHP






Reversing a string by word

 
<?php
    $s = "Once upon a time there was a turtle.";
    
    $words = explode(' ',$s);
    
    $words = array_reverse($words);
    
    $s = implode(' ',$words);
    print $s;
?>
  
  








Related examples in the same category

1.Concisely reversing a string by word
2.Return an array with elements in reverse order
3.Reversing an Array Using array_reverse()
4.array_reverse() function reverses the order of the array elements.