How to sort associative arrays in ascending order in PHP according to value example tutorial using asort() method.
In this php development tutorial we are creating a simple associative array and sort that array in ascending order. So here is the complete step by step tutorial for How to sort associative arrays in ascending order in PHP.
How to sort associative arrays in ascending order in PHP.
Code for associative-arrays.php file.
<!doctype html> <html> <head> <meta charset="utf-8"> <title>Sort associative arrays in ascending order in PHP</title> </head> <body> <?php $count = array("ONE"=>"1", "TWO"=>"2", "THREE"=>"3", "FOUR"=>"4"); asort($count); foreach($count as $i => $i_count) { echo "Table = " . $i . ", Value=" . $i_count; echo "<br>"; } ?> </body> </html>
Screenshot: