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)