over 9 years ago
What is tht asort() function in php ?
The asort() function sorts an associative array in ascending order as reported by the value.
why use asort() function in php ?
asort() is fundamentally used when sorting associative array where the authentic element order is paramount.
You can see below example of asort() function in php.
- <?php
- $employeage=array("Samir"=>"25","Bhuvi"=>"30","Ankit"=>"43");
- //now call the asort() function for sorting associative array
- asort($employeage);
- ////loop rstart for find all value
- foreach($employeage as $key=>$value)
- {
- echo "Name=" . $key . ", Age=" . $value;
- echo "<br>";
- }
- ?>
<?php $employeage=array("Samir"=>"25","Bhuvi"=>"30","Ankit"=>"43"); //now call the asort() function for sorting associative array asort($employeage); ////loop rstart for find all value foreach($employeage as $key=>$value) { echo "Name=" . $key . ", Age=" . $value; echo "<br>"; } ?>
Output will come
Name=Samir, Age=25
Name=Bhuvi, Age=30
Name=Ankit, Age=43
0 Comment(s)