语法错误:“[”意外

时间:2014-12-03 08:22:42

标签: php

显示意外语法错误的PHP代码[在行号1上 我不确定是什么问题。

   $shipping_array = [ "AL" => ["a","c","b"],
    "AZ" => ["b","c","a"],
    "AR" => ["a","c","b"],
    "WI" => ["c","a","b"] ];

3 个答案:

答案 0 :(得分:3)

您使用短数组声明,必须使用PHP 5.4或更高版本。

在PHP 5.4下尝试:

 $shipping_array = array(
    "AL" => array("a","c","b"),
    "AZ" => array("b","c","a"),
    "AR" => array("a","c","b"),
    "WI" => array("c","a","b") 
 );

http://php.net/manual/en/language.types.array.php

答案 1 :(得分:1)

这应该适合你:

$shipping_array = array(
                    "AL" => array("a","c","b"),
                    "AZ" => array("b","c","a"),
                    "AR" => array("a","c","b"),
                    "WI" => array("c","a","b")
                );

如果您使用PHP 5.4或更高版本,则可以使用此功能:

$shipping_array = [
        "AL" => ["a","c","b"],
        "AZ" => ["b","c","a"],
        "AR" => ["a","c","b"],
        "WI" => ["c","a","b"]
    ];

有关详细信息,请查看此处:http://php.net/manual/en/language.types.array.php

答案 2 :(得分:-2)

语法问题你必须尝试这个:

$shipping_array = array( "AL" => array("a","c","b"),
                         "AZ" => array("b","c","a"),
                         "AR" => array("a","c","b"),
                          "WI" => array("c","a","b")
                        );