我從CSV導入的陣列。陣列看起來像這樣添加陣列陣列PHP
Array
(
[0] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CBC
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 4
[Remark2] => TEST
)
[1] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CBD
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 5
[Remark2] => TEST2
)
[2] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CJ
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 5
[Remark2] => TEST3
)
[3] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CL
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 4
[Remark2] => TEST4
)
[4] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CRG
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 4
[Remark2] => TEST5
)
[5] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CRGM
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 4
[Remark2] => TEST6
)
[6] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CRSB
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 4
[Remark2] => TEST7
)
)
但現在我想添加一個會話。所以我的數組會看起來像這樣。
[0] => Array
(
[DOCategory] => IM
[ToCustomerCode] => M-CBC
[ExternalDocNo] => DRDOC-DJ-GBAR10-25
[Item] => S160373
[Quantity] => 4
[Remark2] => TEST
[session] => ....
)
的[session]
從這個
$random = md5(uniqid($userlogin, true));
$new = array('session' => $random);
那麼這裏是我到目前爲止
$x=0;
while(($line = fgetcsv($f)) !== false) {
$data[] = $line;
}
for($x=0;$x<count($data);$x++){
if($x != 0) {
$newArray[] = array_combine($data[0], $data[$x]);
$newArrays[] = $new;
}
}
$newArray = array_push($newArray,$newArrays);
echo "<pre>";print_r($newArray);
試圖從我echo "<pre>";print_r($newArray);
結果是8
。所以我怎麼能達到我想要的。預先感謝並對我的英語不好。
爲什麼不只是使用for或foreach語句遍歷數組並添加會話密鑰/值? – pteronewone