-1

我定义了我的数组

$data = array();

添加了 1 项:

$data['response'] = true;

现在我想一次添加多个项目,例如:

$data["picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2];

但我收到了这个错误:

parse error, expecting `']''

我究竟做错了什么?

4

7 回答 7

5

您可以将其写成多行,例如:

$data['new0'] = 'value0';
$data['new1'] = 'value1';

或使用array_merge(将覆盖碰撞键):

$data = array_merge($data, array('new0' => 'value0', 'new1' => 'value1'));
于 2012-08-02T07:11:01.620 回答
3

需要一一添加,或者使用array_merge方法。

$data["picUpload"] =$pPicUpload;
$data["Album1"] = $Album1;
$data["Album2"] = $Album2;
于 2012-08-02T07:11:04.760 回答
2

您使用的语法不正确。您需要使用 array_merge 功能

$data = array_merge($data, array(
  "picUpload" => $pPicUpload, 
  "Album1" => $Album1, 
  "Album2" => $Album2
));
于 2012-08-02T07:11:36.883 回答
2
$data = array_merge($data, Array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2));
于 2012-08-02T07:11:37.473 回答
1

为什么不只是:

$data["picUpload"] = $pPicUpload;
$data["Album1"] = $Album1;
$data["Album2"] = $Album2;
于 2012-08-02T07:12:04.307 回答
0

试试这个:

$data = array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2);
于 2012-08-02T07:12:17.067 回答
0

试试这个,

$data = array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2);
于 2012-08-02T07:12:54.180 回答