| Viewed 223 times

How to reverse an array in php


How to reverse an array in php

1 Answer
Mohammad Qandeel
Answered
4

The array can be reversed in PHP using the built-in function
through array_reverse function
the array_reverse  function returns an inverse array

Example :

$array    = [1,2,3];
$reversed = array_reverse($array);
print_r($array);
print_r($reversed);

Output

Array
(
    [0] => 1
    [1] => 2
    [2] => 3
)
Array
(
    [0] => 3
    [1] => 2
    [2] => 1
)