0

我有以下代码:

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 ) )
4

3 回答 3

1

尝试

echo "<br />" . $_SESSION['value'][0]['cardValue'];

于 2013-08-02T05:17:10.013 回答
0

用这个

echo "<br />" . $_SESSION['value'][0]['cardValue'];

数组值在索引 0 内

于 2013-08-02T05:19:31.867 回答
0

由于您$cards1是一个数组并且您将此数组分配给$_SESSION['value'][],因此您希望cardValue使用以下命令进行访问:

echo "<br />" . $_SESSION['value'][0]['cardValue'];
于 2013-08-02T05:17:18.123 回答