关于php

时间:2018-04-27 20:56:31

标签: php arrays laravel

我正在尝试读取数组的属性,如下所示:

[
    0 => [
        "address" => "0.0.0.0.0"
        "mac-address" => "XX:XX:XX:XX:XX:XX"
        "server" => "0.0.0.0"
    ]
    1 => [
        "address" => "0.0.0.0"
        "mac-address" => "XX:XX:XX:XX:XX:XX"
        "server" => "0.0.0.0"
    ]
]

如果我这样做

echo $the_array[0]['mac-address'];

它不起作用。

我还尝试将其转换为对象并使用花括号来使用短划线读取属性,但没有运气。

我知道这是一个愚蠢的事情,但我无法弄清楚如何重命名该数组键以使用更友好的分隔符,如下划线。

1 个答案:

答案 0 :(得分:0)

请查看更新的代码,它正常工作,您只是在某些地方错过逗号

$the_array = [
    0 => [
        "address" => "0.0.0.0.0",
        "mac-address" => "XX:XX:XX:XX:XX:XX",
        "server" => "0.0.0.0",
    ],
    1 => [
        "address" => "0.0.0.0",
        "mac-address" => "XX:XX:XX:XX:XX:XX",
        "server" => "0.0.0.0",
    ]
];

echo $the_array[0]['mac-address'];