我定義我的數組如何將項目添加到我的關聯數組中?
$data = array();
增加1項:
$data['response'] = true;
現在我想在添加多個項目曾經這樣:
$data["picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2];
但我得到這個錯誤:
parse error, expecting `']''
我在做什麼錯?
我定義我的數組如何將項目添加到我的關聯數組中?
$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;
,因爲我知道這是可以做到這一點,因爲我描述,我想了解爲什麼它不適合我 – 2012-08-02 07:19:14
學習新東西總是很好:) – 2012-08-02 07:26:54
試試這個:
$data = array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2);
試試這個,
$data = array("picUpload" => $pPicUpload, "Album1" => $Album1, "Album2" => $Album2);
這不是什麼保羅問:) – 2012-08-02 07:13:33
$ data = array(「picUpload」=> $ pPicUpload,「Album1」=> $ Album1,「Album2」=> $ Album2); – Debugger 2012-08-02 07:12:19