0

私は基本的に一意の数を数える必要がある大きな配列を持っています: 例の配列

最終結果私は次のようなものを探しています

$result = array(
    'A3D5' => array('P2' => 1, 'P3' => 1, 'P4' => 1, 'total' => 3),
    'AE5S' => array('P4' => 1, 'total' => 1)
);

私は徹底的に調べてみましたが、それらを別のキーに分類する方法を理解できないようです$zone = "P{$array['zone']}"; $result[$zone][$prestige]++

4

1 に答える 1

0
$array = array(
    "denizen" => array
        (
            "prestige" => 2,
            "zone" => "A3D5",
            "scope_frag" => 765
        ),

    "생각" => array
        (
            "prestige" => 4,
            "zone" => "A3D5",
            "scope_frag" => 135
        ),

    "Ryans" => array
        (
            "prestige" => 3,
            "zone" => "A3D5",
            "scope_frag" => 78
        ),

    "지적인" => array
        (
            "prestige" => 2,
            "zone" => "AE5S",
            "scope_frag" => 481
        )
);
foreach ($array as $group) {
    $zones[$group["zone"]][] = $group["prestige"];
}
foreach ($zones as $name => $zone) {
    $total = count($zone);
    foreach ($zone as $prestige) {
        $result[$name]["P".$prestige] += 1;
    }
    ksort($result[$name]);
    $result[$name]["total"] = $total;
}
echo "<pre>";
print_r($result);
echo "</pre>";
于 2013-02-06T03:12:53.097 に答える