-3

I have a simple PHP blackjack script that I seem to be getting errors in.

The part of code causing the problem is this;

function evaluateHand($hand) {
    global $faces;
    $value = 0;
    foreach ($hand as $card) {
        if ($value > 11 && $card['face'] == 'a') {
            $value = $value + 1;
        }
        else {
            $value = intval($value) + intval($faces[$card['face']]); <----- error
        }
    }
    return $value;
}

The error is "Warning: Illegal offset 'face'" on the line I've pointed to above.

What's causing this? Or how I could fix it?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user961882
  • 227
  • 5
  • 10

1 Answers1

0

Illegal offset means you are requesting an array key that doesn't exist. In this case, the array in $card has no key face when the error is thrown.

dersam
  • 106
  • 1
  • 4