suite = $s; $this->face = $f; } // return card as string public function displayText() { return "{$this->face} of {$this->suite}s"; } // return rank of card for poker 0 to 13 public function pokerRank() { return array_search($this->face, Deck::$faces); // find face in faces and return index } } // a class for a Deck of cards class Deck { // static will allow access without objects public static $suites = array ( 'club', 'diamond', 'spade', 'heart' ); public static $faces = array ( 'ace', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'jack', 'queen', 'king' ); private $cards; // deck of Card objects function __construct() { $this->rebuild(); } // rebuild 52 card random deck public function rebuild() { $this->cards = array(); foreach( Deck::$suites as $s ) { foreach( Deck::$faces as $f ) { array_push($this->cards, new Card($f, $s)); // build deck one by one } } $this->shuffle(); } public function shuffle() { shuffle($this->cards); } // deal a card, return NULL public function dealOne() { return array_pop($this->cards); // pop on off deck } public function cardsLeft() { // cards left in deck return count($this->cards); } } ?>