我有以下代碼:無法訪問多維關聯數組
foreach ($cardSuits as $cardSuit) {
$keyCardValues = array_keys($cardValues);
foreach ($keyCardValues as $cardValue) {
$deck[] = array("cardValue" => $cardValue, "cardSuit" => $cardSuit);
shuffle($deck);
}
}
if ($deal == "Deal") {
shuffle($deck);
$cards1 = array_shift($deck);
$_SESSION['value'][] = $cards1;
我已經試過:
echo "<br />" . $_SESSION['value']['cardValue'];
但它給我一個未定義的索引錯誤。但是,如果我做一個print_r,它工作正常.. 我如何回顯它,所以會話可以給我$ cardValue數組中?
感謝
編輯爲print_r的:
Array ([value] => Array ([0] => Array ([cardValue] => nine [cardSuit] => hearts)) [cards] => Array ([0] => 9 [1] => 2 [2] => 10 [3] => 4 [4] => 3 [5] => 10 [6] => 5 [7] => 2 [8] => 10 [9] => 5))
編輯回聲的print_r:
Array ([value] => Array ([0] => Array ([cardValue] => nine [cardSuit] => diamonds)) [cards] => Array ([0] => 9 [1] => 3 [2] => 7 [3] => 10 [4] => 9 [5] => 11 [6] => 7 [7] => 10 [8] => 10 [9] => 5))
內你可以發佈'echo print_r($ _ SESSION)的結果;' –
$ _SESSION ['value']是數組。使用foreach –
添加print_r謝謝 – StevenWin