asort()
and arsort()
functionThe PHP asort()
and arsort()
functions can be used for sorting an array by value. The following section will show you how these functions basically work.
You can use the asort()
function for sorting an associative array by value alphabetically in the ascending order, while maintaining the relationship between key and data.
<?php
$fruits = array("b"=>"banana", "a"=>"apple", "d"=>"dog", "c"=>"cat");
// Sorting the array by value
asort($fruits);
print_r($fruits);
?>
You can use the arsort()
function for ssorting an associative array by value alphabetically in the descending order, while maintaining the relationship between key and data.
<?php
$fruits = array("b"=>"banana", "a"=>"apple", "d"=>"dog", "c"=>"cat");
// Sorting the array by value
arsort($fruits);
print_r($fruits);
?>
Hi, My name is Harsukh Makwana. i have been work with many programming language like php, python, javascript, node, react, anguler, etc.. since last 5 year. if you have any issue or want me hire then contact me on [email protected]
How to Create Custom Blade Directive in Laravel
Laravel blade is simple template engine...How to check if element exists in jQuery and JavaScript
When you do some change in elements, som...Optimize your Laravel Application for High Performance
Laravel has proved best PHP framework fo...Javascript setTimeout and clearTimeout method
Sometimes, you may want to execute Javas...Laravel 8 - Excel and CSV Import Export to Database using maatwebsite/excel with Example.
Excel file import-export to the database...