0

我拥有的数组:

N ==1 匹配结果 1 N ==2 匹配结果 0 N ==3 匹配结果 2

只有匹配结果 1 到 CHEALSEA 匹配 (N=3)

$match = [
[
    'team' => 'Barcelona Realmadrid',
    'odd' => [
        'matchresult' => [
            0 => [
                'N' => '1',
                'O' => '1.25',
            ],
            1 => [
                'N' => '2',
                'O' => '4',
            ],
            2 => [
                'N' => '3',
                'O' => '6',
            ]
        ]
    ],
],
[
    'team' => 'Chelsea - Celtic',
    'odd' => [
        'matchresult' => [
            0 => [
                'N' => '3',
                'O' => '8',
            ],
        ]
    ],
],
];

我可以像这样得到我想要的结果。如何以更短的方式使用功能?

foreach($match as $index => $item){
$matchresult = $item["odd"]["matchresult"];
$n1 = array_keys(array_column($matchresult, 'N'), 1);
$n2 = array_keys(array_column($matchresult, 'N'), 2);
$n3 = array_keys(array_column($matchresult, 'N'), 3);
echo "matchresult 1 = ".$item["odd"]["matchresult"][$n1[0]]["O"];
echo "matchresultu X = ".$item["odd"]["matchresult"][$n2[0]]["O"];
echo "matchresult 2 = ".$item["odd"]["matchresult"][$n3[0]]["O"];
echo "<BR>";
}

正是我试图产生的输出:

teams                  1      X       2    
-------------------  ------  ----   -----
Barcelona Realmadrid  1.25   4.00    6.00
Chelsea - Celtic       -      -      8.00
4

0 回答 0