<?php
class Deck{
public $cards = array();
//creates an instance of a deck of cards (works)
public function __construct(){
$values =array('2','3','4','5','6','7','8','9','10','J','Q','K','A');
$suits =array('Diamond','Club','Heart','Spade');
foreach ($suits as $suit) {
foreach($values as $value){
$this->cards[] = "$value of $suit's";
}
}
}
public function numberOfDecks($number){
$cards = $this->cards;
$this->number = $number;
for($i = 0 ; $i < $number; $i++){
$this->cards = array_merge($this->cards, $cards);
}
}
}
$deck = new Deck();//works as expected
// how many cards are intially constructed?
echo "count of cards in new deck: " . count($deck->cards) . "\n<br/>\n";
// add 3 more decks of cards
$deck->numberOfDecks(3);//trouble
echo "count of cards after adding 3 decks: " . count($deck->cards);
// $shuffled = shuffle($deck->cards);//works as expected
// var_dump($deck);