我想添加陣列(數據來自URL)到一個會話陣列:加入數組到session數組在PHP
$nbA = array(); $nbE = array(); $nbS = array(); $nbAll = array();
for ($a = 1; $a <= $_GET['nbAdultes']; $a++) { $nbA[] .= "ADULTE"; }
for ($e = 1; $e <= $_GET['nbEnfants']; $e++) { $nbE[] .= "ENFANT"; }
for ($s = 1; $s <= $_GET['nbSeniors']; $s++) { $nbS[] .= "SENIOR"; }
$nbAll = array_merge($nbA, $nbE, $nbS);
$nbAllSession = array_merge($nbAll, $nbAll);
$_SESSION['nbAllSession'] = $nbAllSession;
print_r($nbAllSession);
print_r($nbAll);
屆陣列一直只顯示2 陣列。
它應該是這樣的:
1. Array ([0] => ADULTE [1] => ENFANT [2] => ENFANT)
2. Array ([0] => ADULTE [1] => ADULTE [2] => ENFANT)
最後的會話陣列:
Array ([0] => ADULTE [1] => ENFANT [2] => ENFANT [3] => ADULTE [4] => ADULTE [5] => ENFANT)
'$ _SESSION [ 'nbAllSession'] [] = $ nbAllSession;'變化這樣和checck –
同樣的事情...... – Clementine
爲什麼這樣? '$ nbAllSession = array_merge($ nbAll,$ nbAll);' – CatalinB