Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to use of "ksort" in php

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 375
    Comment on it

    Firstly we will know what is the use of "ksort" in php

    "ksort" is used to sort the array by key and this is useful for associative arrays.

    You can see below example for "ksort".

     <?php
    
       //suppose we want sort employee age from an array list
    
            //firstly create a varibale and store all array list 
            $EmployeeAge=array("Mac"=>"25","Mical"=>"22","Bane"=>"43");
            //here $EmployeeAge is a variable  in which  store all array data list
    
              //use of ksort()
               ksort($EmployeeAge);
    
             // Loop through the array till we find the key and value
             foreach($EmployeeAge as $age=>$age_value)
                {
                echo "Key=" . $age . ", Value=" . $age_value;
                echo "<br>";
                }
       ?>
    

    output will come

    Key=Bane,  Value=43
    Key=Mac,   Value=25
    Key=Mical, Value=22

 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: