This time for everyone to bring PHP according to the size of a key value array method, PHP according to the size of a key value of the array of considerations, the following is the actual case, together to see.
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 Implementation request refund steps in detail
Php namespace namespace definition and import use case analysis