Reverse in PHP

Reverse a string by PHP function strrev

echo strrev("Hello world!");

Result: !dlrow olleH

Reverse words in string

$input_string = 'Hello world! Please reverse my words!';
echo implode(' ', array_reverse(explode(' ', $input_string)));

Result: words! my reverse Please world! Hello

Reverse array items by PHP function array_reverse

$input_array = array(3 , 1, "zero", true);
$reversed_array = array_reverse($input_array);
print_R($reversed_array);

Result: Array ( [0] => 1 [1] => zero [2] => 1 [3] => 3 )

Continue reading Reverse in PHP