Php Array Elements Reverse Function

What is array_reverse Function?

Explanation

The "array_reverse" function returns an array with elements in reverse order.

Syntax:


array_reverse(array,preserve)

In the above syntax "array" specifies the array, "preserve" is used to preserve the array keys, it can either be true or false.

Example :


<?php
$b=array("c"=>"Cherry","b"=>"Strawberry");
print_r(array_reverse($b);
?>
Result :

Array ([b]=> Strawberry, [c]=> Cherry)

In the above example the function returns the array elements in the reverse order.

PHP Topics


Ask Questions

Ask Question