Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Sorting function in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 152
    Comment on it

    Php sorting function of an array:

    •  sort()  -This will sort an arrays in ascending order.
    •  rsort() -This will sort arrays in descending order
    •  asort() -This function will sort associative arrays in ascending order, according to the value.
    •  ksort() -By using the associative arrays it will sort in ascending order,according to a key.


    For Example:

    
    <?php
    
    $val=array("rose","lotus","marigold");
    sort($val);
    $age =array("mohan"=>"30", "ram"=>"35", "sohan"=>"40");
    asort($age);
    
    $length = count($cars);
    for($x=0; $x<=lenght; $x++)
    {
         echo $val[$x];
         echo "<br>";
    }
    foreach($age as $x => $x_value)
    {
       echo "key=" . $x . ", Value=" . $x_value;
       echo "<br>";
    }
    ?>

    This will sort an array in ascending order according to the values  passes to it.

 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: