PHP two-dimensional array sorting simple implementation method, PHP two-dimensional array sorting
In this paper, the simple implementation method of PHP two-dimensional array ordering is described. Share to everyone for your reference, as follows:
function Multi_compare ($a, $b) { $val _arr = Array ( ' gold ' = ' asc ', ' silver ' = ' desc '///can also add additional sorting criteria ); foreach ($val _arr as $key = + $val) { if ($a [$key] = = $b [$key]) { continue; } Return (($val = = ' desc ') -1:1) * (($a [$key] < $b [$key]) -1:1); } return 0;} $arr = Array ( ' Gold ' =>1, ' Silver ' =>2), array ( ' Gold ' =>8, ' Silver ' =>10), Array (' Gold ' =>8, ' Silver ' =>8), array (' Gold ' =>2, ' Silver ' =>1), Uasort ($arr, ' Multi_compare ');p Rint_r ($ ARR);
The results of the operation are as follows:
Array ( [0] = = Array ( [gold] = 1 [Silver] = 2 ) [3] = = Array ( [Gold] = > 2 [silver] + 1 ) [1] = = Array ( [Gold] = 8 [silver] + ) [2 ] = = Array ( [Gold] = 8 [Silver] = 8 ))
More about PHP related content readers can view the topic: "Summary of PHP sorting algorithm", "PHP Basic Grammar Introductory Tutorial", "PHP error and Exception handling method summary" and "PHP common functions and Skills summary"
I hope this article is helpful to you in PHP programming.
Articles you may be interested in:
- A detailed approach to the problem of two-dimensional array sorting in PHP
- How to sort multidimensional arrays in PHP Array_multisort
- PHP dedicated array sorting class Arraysortutil usage instance
- How PHP sorts an array by using the sort () function
- PHP implementation of the specified field of multi-dimensional array sorting function sharing
- An example of array sorting using PHP selection sorting
- Example of array sorting using PHP insertion sorting
- PHP array sorting usort, uksort, and sort function usage
- Example of sort, asort, and ksort usages of PHP array ordering
- Two-dimensional array ordering for PHP instance sharing
- PHP two-dimensional array sorting 3 ways and custom function sharing
- A function sharing of a PHP two-dimensional array ordering
- PHP two-dimensional array sorting method (Array_multisort usort)
- PHP two-dimensional array sorting detailed
http://www.bkjia.com/PHPjc/1099062.html www.bkjia.com true http://www.bkjia.com/PHPjc/1099062.html techarticle php Two-dimensional array sorting simple implementation method, PHP two-dimensional array sorting This paper describes the simple implementation of PHP two-dimensional array ordering. Share to everyone for your reference, specifically as follows: Func ...