【发布时间】:2012-07-17 14:58:28
【问题描述】:
我有一个复杂的多维数组。结构是这样的
Array
(
[0] => Array
(
[countries] => Array
(
[0] => Array
(
[country_code] => US
[growth] => 3.57
)
[1] => Array
(
[country_code] => CA
[growth] => 4.77
)
[2] => Array
(
[country_code] => TT
[growth] => 0
)
)
[group_name] => North America
)
[1] => Array
(
[countries] => Array
(
[0] => Array
(
[country_code] => BR
[growth] => 2.19
)
[1] => Array
(
[country_code] => PE
[growth] => 1.78
)
[2] => Array
(
[country_code] => UY
[growth] => 8.83
)
[3] => Array
(
[country_code] => MX
[growth] => 3.83
)
)
[group_name] => South America
)
)
我想对它们进行排序(可能使用array_multisort),以便它们根据growth(最高优先)进行排序
这样排序后的数组就会是
Array
(
[0] => Array
(
[countries] => Array
(
[0] => Array
(
[country_code] => CA
[growth] => 4.77
)
[1] => Array
(
[country_code] => US
[growth] => 3.57
)
[2] => Array
(
[country_code] => TT
[growth] => 0
)
)
[group_name] => North America
)
[1] => Array
(
[countries] => Array
(
[0] => Array
(
[country_code] => UY
[growth] => 8.83
)
[1] => Array
(
[country_code] => MX
[growth] => 3.83
)
[2] => Array
(
[country_code] => BR
[growth] => 2.19
)
[3] => Array
(
[country_code] => PE
[growth] => 1.78
)
)
[group_name] => South America
)
)
我是 PHP 新手,所以我不知道如何对这个复杂的数组进行排序。我知道如何对简单的多维数组进行排序,如http://in2.php.net/manual/en/function.array-multisort.php中所示
【问题讨论】:
-
我想对一个复杂的数组进行排序,但我不知道该怎么做。我已经阅读了手册,但找不到这样一个复杂数组的好例子。
标签: php sorting multidimensional-array