Hello,
I'm creating a php blackjack (21) game, and need some help creating a function that will select a random card, that is not already in use.
Ultimately I want to be able to define a new, unused card as simply as going:
$new_card = newCard();
I've looked at a few ways of going about this, and really just need someone to help me put it together.
PHP Code:
function newCard(){
$all_cards = range(1, 52); $used_cards = array(); $card = rand($all_cards[0], $all_cards[51]);
while (in_array($card, $all_cards)){ // not sure what to do here to here. }
$used_cards = array_push($used_cards, $card); // I want this to add whatever card to the used cards array, so it can't be used again. return $card; }
I'd be over the moon if someone could help me with this  !
|