How to use array reverse in PHP

In this article, I will explain how the array_reverse() function can be used in PHP.
  • 1702

array_reverse() function in PHP

The array_reverse() function is used to returns an array in the reverse order.

Syntax

array_reverse(array,preserve)

Parameter

  • array  array is required parameter. Specifies an array.

  • preserve number is Optional parameter. Default value of preserve is false. Possible value

    • true
    • false

Example

The following example show to how the array_reverse() function can be used in PHP.

<html>

<body>

<h3 style="color: blue;">array_reverse() function example in PHP</h3>  

    <?php 

    $a= array(1,2,3,4,5);

    $x = array_reverse($a); 

    echo "Current Array value </br>";

    print_r($a); 

    echo "</br> After reverse function value<br/>";

    print_r($x);

    ?> 

</body>

</html>

 

Output

reverse.jpg

You may also want to read these related articles here
 
Ask Your Question 
 
Got a programming related question? You may want to post your question here
 

Categories

More Articles

© 2019 DotNetHeaven. All rights reserved.