我定义了我的数组
$data = array();
添加了 1 项:
$data['response'] = true;
现在我想一次添加多个项目,例如:
$data["picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2];
但我收到了这个错误:
parse error, expecting `']''
我究竟做错了什么?
您可以将其写成多行,例如:
$data['new0'] = 'value0';
$data['new1'] = 'value1';
或使用array_merge(将覆盖碰撞键):
$data = array_merge($data, array('new0' => 'value0', 'new1' => 'value1'));
需要一一添加,或者使用array_merge
方法。
$data["picUpload"] =$pPicUpload;
$data["Album1"] = $Album1;
$data["Album2"] = $Album2;
您使用的语法不正确。您需要使用 array_merge 功能
$data = array_merge($data, array(
"picUpload" => $pPicUpload,
"Album1" => $Album1,
"Album2" => $Album2
));
$data = array_merge($data, Array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2));
为什么不只是:
$data["picUpload"] = $pPicUpload;
$data["Album1"] = $Album1;
$data["Album2"] = $Album2;
试试这个:
$data = array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2);
试试这个,
$data = array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2);