Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Use of array_reverse() function in PHP

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 265
    Comment on it

    Hi Reader's,
     Welcome to FindNerd, today we are going to discuss use of array_reverse() function in PHP.

    This function is used  to reset the index of elements and returns the reversed array.array_reverse() function accepts array as a argument and contain all values as a array and return in inversion order.

    This function is always preserved for numeric keys.This function will preserve the keys if the value of preserve key is TRUE and default value is FALSE.

    If you will not pass TRUE value then this function reverse only array list and when you will pass TRUE value then it will reverse index and array list both.

    Syntax of array_reverse() function

     array_reverse(array, preserve_keys)

    There are two main parameter of this function

    1-array :This parameter is specifies an input array and it is a required parameter.
    2-preserve_keys :This is optional parameter and that is set on TRUE or FALSE.

    You can see below example:

    <?php
         //define here a array list of name
        $Namearr= array(Toc, Mac, Jolly, bruno, Jiyo);
        //call array_reverse() function without set value
        $result = array_reverse($Namearr);
        //call array_reverse() function with set value TRUE
        $preArr = array_reverse($Namearr,true);
        //print the result
        print_r($result);
        echo '</br>';
        //print the preArr
        print_r($preArr);
    
      ?>

    Output will come following of above example

    Array ( [0] => Jiyo [1] => bruno [2] => Jolly [3] => Mac [4] => Toc )
    Array ( [4] => Jiyo [3] => bruno [2] => Jolly [1] => Mac [0] => Toc ) 
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: