0

我开发了一个排名系统。我得到以下数组:

[1] => Array
    (
        [botarin - Branding und Kommunikation] => 1
        [Raiffeisen Kredit 2 Go] => 2
    )

[2] => Array
    (
        [Kindersteckdosen] => 1
        [Surf lieber mit bob] => 1
        [Lafarge Imageinserate] => 1
        [MCG Messecongress Graz Inserate] => 1
    )

1,2 是类别 ID,然后是项目名称和每个项目的票数。我如何对数组进行排序,所以类别 ID 保持这样排序,但项目名称按投票数降序排列?

有任何想法吗?

提前致谢!

4

3 回答 3

3
// $full_array is your array of category ID's with projects/votes as nested arrays

foreach ($full_array as $cat_id => $projects) {
    asort($projects, SORT_NUMERIC);
    $full_array[$cat_id] = $projects;
}

// Each category ID  within $full_array is now sorted
于 2009-10-07T23:31:43.367 回答
0

遍历数组。对于每个子数组,使用asort

于 2009-10-07T23:30:00.387 回答
0

要按降序排序,请使用arsort()

$a = array( "a" => 2 );
arsort( $a );
print_r( $a );
于 2009-10-07T23:37:05.890 回答