This time, we'll bring you a PHP custom two-dimensional array sort function array,php custom two-dimensional array sorting function what are the considerations for array, here is the actual case, take a look.
This article mainly introduces the PHP custom two-dimensional array sorting function Array_orderby usage, combined with the example of PHP for two-dimensional array to sort the related traversal, determination, sequencing and other operational skills, the need for friends can refer to the next
This article describes the PHP custom two-dimensional array ordering function Array_orderby usage. Share to everyone for your reference, as follows:
<?php/**i came up with a easy to sort database-style results. This does-example 3 does, except it takes care of creating those intermediate arrays for you before passing control O N to Array_multisort (). */function Array_orderby () {$args = Func_get_args (); $data = Array_shift ($args); foreach ($args as $n = + $field) {if (is_string ($field)) {$tmp = array (); foreach ($data as $key = + $row) $tmp [$key] = $row [$field]; $args [$n] = $tmp; }} $args [] = & $data; Call_user_func_array (' Array_multisort ', $args); Return Array_pop ($args);} /*the sorted array is now with the return value of the function instead of being passed by reference.*/$data [] = Array (' Volu Me ' = ' Edition ' + 2); $data [] = Array (' volume ' = 85, ' edition ' = 1); $data [] = Array (' volume ' =, ' Edition ' + 6); $data [] = Array (' volume ' = = 98, ' edition ' = + 2); $data [] = Array (' volume ' = N, ' edition ' => ; 6); $data [] = Array (' volume ' = +, ' EdItion ' + 7);//Pass the array, followed by the column names and sort flags$sorted = Array_orderby ($data, ' volume ', SOR T_desc, ' edition ', SORT_ASC);p rint_r ($sorted)?>
Operation Result:
Array ( [0] = = Array ( [Volume] = 98 [Edition] = 2 ) [1] = = Array ( [ Volume] [ Edition] = 1 ) [2] = = Array ( [Volume] = [ Edition] = 6< c14/>) [3] = = Array ( [Volume] = [Edition] = 6 ) [4] = = Array ( [Volume] = [Edition] + 2 ) [5] = = Array ([volume] = [ Edition] = 7 ))
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
How the PHP generator uses
phpstudy2018 Access to directory service permissions
thinkphp Implementation Payment (JSAPI payment) process Tutorial _php instance