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

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 158
    Comment on it

    Sort() function is used to sort array in ascending order.

    Example:

        <?php
         $numbers = array(9, 6, 3, 22, 12);
         sort($numbers);
         $length = count($numbers);
         for($x = 0; $x <  $length; $x++) {
         echo $numbers[$x];
         echo "<br>";
         }
        ?>
    

    Output : 3, 6, 9, 12 , 22


    rsort() function is used to sort Array in descending order
    Example:

      <?php
             $numbers = array(9, 6, 3, 22, 12);
             rsort($numbers);
             $length = count($numbers);
             for($x = 0; $x <  $length; $x++) {
             echo $numbers[$x];
             echo "<br>";
             }
            ?>
    

    Output : 22, 12, 9, 6, 3

 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: