循环进入数组停电,用PHP响应键

时间:2019-04-30 02:49:22

标签: php arrays

我在PHP中具有以下数组:

Array
(
    [CA] => Array
        [country] => Canada
        (
            [0] => Array
                (
                    [name] => BSB
                    [example] => 123456
                    [length] => 6 characters
                )

            [1] => Array
                (
                    [name] => Account Number
                    [example] => 12345678
                    [length] => 6 to 10 characters
                )

        )
)

如何在不回显国家名称[country] => Canada的情况下循环到此数组中?

实际上,我有这个:

foreach($array['CA'] as $key => $value) {
    ...
}

但是会打印国家名称。

谢谢。

1 个答案:

答案 0 :(得分:1)

我们可以这样吗

foreach($array['CA']['country'] as $key => $value) {
    ...
}

相反,

foreach($array['CA'] as $key => $value) {
    ...
}