我是PHP新手。我正在尝试为分配给变量的数组使用new(ish)格式的方括号。
这是旧格式:
$header = array('Accept: application/json','Content-Type: application/json','Authorization: Bearer ACCESSTOKEN','x-api-key: APIKEY','x-proxy-global-company-id: COMPANYID');
这是本教程针对新刹车样式的讨论:
$array = [
"foo" => "bar",
"bar" => "foo",
];
?>
我想要的项目类似于标题中的以下内容:
Accept: application/json
Content-Type: application/json
Authorization: Bearer ACCESSTOKEN
x-api-key: APIKEY
x-proxy-global-company-id: COMPANYID
因此,我认为应该为我的标头变量分配一个像这样的数组:
$header = [
"Accept: application/json",
"Content-Type: application/json",
"Authorization: Bearer ACCESSTOKEN",
"x-api-key: APIKEY",
"x-proxy-global-company-id: COMPANYID",
];
这没有验证,所以我知道我错了。它在第5行显示意外的T字符串。有人可以给我提示我哪里出错了吗?
答案 0 :(得分:0)
您的标题应如下所示:
$header = [
"Accept" => "application/json",
"Content-Type" => "application/json",
"Authorization" => "Bearer ACCESSTOKEN",
"x-api-key" => "APIKEY",
"x-proxy-global-company-id" => "COMPANYID",
];