Sort PHP Array
There is some predefined PHP functions for array sorting. These functions perform different type sorting for the array:-
Function name | Sorts by | Order of sort | Related functions |
---|---|---|---|
array_multisort() | value | first array or sort options | array_walk() |
asort() | value | low to high | arsort() |
arsort() | value | high to low | asort() |
krsort() | key | high to low | ksort() |
ksort() | key | low to high | asort() |
natcasesort() | value | natural, case insensitive | natsort() |
natsort() | value | natural | natcasesort() |
rsort() | value | high to low | sort() |
shuffle() | value | random | array_rand() |
sort() | value | low to high | rsort() |
uasort() | value | user defined | uksort() |
uksort() | key | user defined | uasort() |
usort() | value | user defined | uasort() |
Examples of these functions:-
1. array_multisort()
This function used many types and sort indexed array, associative array, and multiple arrays at a time. Normally it sort in ascending order, see the example:-$data=array("A","D","H","B","Z"); array_multisort($data); print_r($data); //output:- Array ( [0] => A [1] => B [2] => D [3] => H [4] => Z )
2. asort()
This function sort according to the value of all types of array and it is sorted in ascending order of array values, see the example:-
$agedata=array("amit"=>"45","dinesh"=>"55","ramu"=>"25"); asort($agedata); //output:- Array ( [ramu] => 25 [amit] => 45 [2] => D [dinesh] => 55 [4] => Z )
6 Comments
Thanks for sharing this valuable information to our vision. You have posted a worthy blog keep sharing. really nice
ReplyDeleteAi & Artificial Intelligence Course in Chennai
PHP Training in Chennai
Ethical Hacking Course in Chennai Blue Prism Training in Chennai
UiPath Training in Chennai
GlassWire Elite Crack is a powerful program to discover hidden threats on your computer. This program efficiently detects a malware, .GlassWire Pro Elite Crack
ReplyDeleteStep 2: Open the Application "Beyond Compare 4". Navigate To "Help >> Enter Key". Step 3: Paste the Above mentioned Key again. Now, it should Activate. Thanks .Beyond Compare 3 Key
ReplyDeleteThanks greaat blog
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteYou are constantly manifesting your reality, even if you are not always aware of it. According to the Law of Attraction, like attracts like. The .How-To-Manifest-A-Car-With-The-Law-Of-Attraction
ReplyDelete