Introduction: This is a detailed page of several array sorting methods in PHP. It introduces PHP, related knowledge, skills, experience, and some PHP source code.
Class = 'pingjiaf' frameborder = '0' src = 'HTTP: // biancheng.dnbc?info/pingjia.php? Id = 336874 'rolling = 'no'>
1. Simple array sorting (the key names of the original array will be ignored)
Sort ($ ARR) rsort ($ ARR)
2. Sort the array by key name
Ksort ($ ARR) krsort ($ ARR)
3. Sort the Array Based on the element value (Reserve key => value relationship)
Asort ($ ARR) arsort ($ ARR)
4. Natural Number sorting method
Natsort ($ ARR) // sorts the natural numbers that ignore case sensitivity. natcasesort ($ ARR)
5. Examples of using the usort () method (custom sorting method)
$ Lamp = array ("Linux", "Apache", "MySQL", "php"); usort ($ lamp, "sortbylen"); function sortbylen ($ one, $ two) {If (strlen ($ one) = strlen ($ Two) return 0; elsereturn (strlen ($ one) <strlen ($ Two ))? 1:-1;} print_r ($ lamp); echo '<br> ';
More articles on how to sort arrays in PHP
Love J2EE follow Java Michael Jackson video station JSON online tools
Http://biancheng.dnbcw.info/php/336874.html pageno: 9.