How do you do this time? According to the size of the array of key value sorting, implementation of the array according to the size of the key value of the order of attention, the following is the actual case, together to see.
The example in this article describes how the PHP implementation sorts based on the size of a key value in an array. Share to everyone for your reference, as follows:
problem: sorting key values for a key of a given array
Workaround:
$a is a sorted array, $b is a collection of data to sort, $result is the final result $b = Array (' name ' = ' = ' Beijing ', ' nums ' = ' + '), Array (' name ' = = ' Shanghai ', ' nums ', ' + ', ' array ' (' name ' = ' + ' guangzhou ', ' nums ' + ') '), Array (' name ' = ' = ' shenzhen ', ' nums ' = ' 70 ') ), $a = Array (), foreach ($b as $key = = $val) { $a [] = $val [' nums '];//here to note $val[' nums '] cannot be empty, otherwise there will be a problem}//$ A first sorts rsort ($a), $a = array_flip ($a), $result = Array (), and foreach ($b as $k + = $v) { $temp 1 = $v [' nums ']; $temp 2 = $a [$temp 1]; $result [$temp 2] = $v;} Here also to sort $result, Jian's position is not ksort ($result);//Then you want to see the results of Var_dump ($result);
Operation Result:
Array (4) {[0]=> Array (2) { ["name"]=> string (4) "Beijing" ["Nums"]=> string (3) "$"} [1]=> Array (2) { ["name"]=> string (4) "Guangzhou" ["Nums"]=> string (3) ""} [2]=> Array (2) { [" Name "]=> string (4)" Shanghai " [" Nums "]=> string (2)" a "} [3]=> Array (2) { [" name "]=> String (4) "Shenzhen" ["Nums"]=> string (2) "70"}}
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:
PHP implements Routing and class auto-loading
Bindparam and Bindvalue in the Yii2 of the use of the detailed