PHP program to reverse an array

Write a PHP program to reverse an array


In this tutorial, you will learn how to reverse an array in php.

Below is the php script to reverse an array in php.

<html>
<head>
    <title>PHP program to reverse an array</title>
</head>
<body>

    <h2>Write a PHP program to reverse an array</h2>
       
    <?php
        $colors = array("red","green","blue");
        $count = sizeof($colors);

        echo "Count of the given array is: ".$count."<br>";
        echo "Before Reverse Operation</br>";

        for ($i=0; $i<$count; $i++)
        {
            echo "$colors[$i]<br>";
        }

        echo "<br>After Reverse Operation</br>";
       
        for ($i=$count-1; $i>=0; $i--)
        {
            echo "$colors[$i]<br>";
        }
    ?>

</body>
</html>


Thanks for reading.