正确的三维数组符号

时间:2016-01-12 08:31:14

标签: php arrays

如果这是三维数组中的正确表示法,我有点怀疑。这只是我的代码的一部分,但是当我运行代码时,我得到一个错误,它说我需要'。

$property = array(
    "green" => array(
        "numbers" => array(1 => "#ffffff"
    ),
    "yellow" => array(
        "numbers" => array(6 => "#81c77d"
    ),
    "white" => array(
        "numbers" => array(24 => "#81e87c"
    ),
    "grey" => array(
        "numbers" => array(0 => "#ffffff"
    ),
    "red" => array(
        "numbers" => array(34 => "#dfb07b"
    )
);

3 个答案:

答案 0 :(得分:1)

你缺少括号 - 他们总是需要配对。它应该是这样的:

$property = array(
    "green" => array(
        "numbers" => array(1 => "#ffffff")
    ),
    "yellow" => array(
        "numbers" => array(6 => "#81c77d")
    ),
    "white" => array(
        "numbers" => array(24 => "#81e87c")
    ),
    "grey" => array(
        "numbers" => array(0 => "#ffffff")
    ),
    "red" => array(
        "numbers" => array(34 => "#dfb07b")
    )
);

使用像Eclipse或Aptana Studio这样的IDE,它会在您输入时显示语法错误,这样您就不必运行代码来查看错误。

答案 1 :(得分:1)

$property = array(
    "green" => array(
        "numbers" => array(1 => "#ffffff")
    ),
"yellow" => array(
    "numbers" => array(6 => "#81c77d")
),
"white" => array(
    "numbers" => array(24 => "#81e87c")
),
"grey" => array(
    "numbers" => array(0 => "#ffffff")
),
"red" => array(
    "numbers" => array(34 => "#dfb07b")
)
);

十六进制代码后的括号

答案 2 :(得分:1)

$property = array(
    "green" => array(
        "numbers" => array(1 => "#ffffff")
    ),
    "yellow" => array(
        "numbers" => array(6 => "#81c77d")
    ),
    "white" => array(
        "numbers" => array(24 => "#81e87c")
    ),
    "grey" => array(
        "numbers" => array(0 => "#ffffff")
    ),
    "red" => array(
        "numbers" => array(34 => "#dfb07b")
    ),
);

你错过了括号。