I'm a total newb to PHP and I'm having a logic problem in my code (array_rand($arrCards,1) is running out of elements before it should). So I've done a var_dump of the array and I get this output (brief excerpt):
array (size=52)
0 =>
object(Card)[2]
private 'suit' => string 'heart' (length=5)
private 'rank' => string 'a' (length=1)
1 =>
object(Card)[3]
private 'suit' => string 'heart' (length=5)
private 'rank' => string '2' (length=1)
2 =>
object(Card)[4]
private 'suit' => string 'heart' (length=5)
private 'rank' => string '3' (length=1)
What I don't understand is the index in 'object(Card)[index]'. It seems to hint as to why the array_rand() is running out of elements.
Here's my Card class:
class Card {
//properties
private $suit;
private $rank;
//constructor
public function __construct($r, $s) {
$this->rank = $r;
$this->suit = $s;
}
//methods
public function getSuit() {
return $suit;
}
public function getRank() {
return $rank;
}
}
And here is how I create each card and push it into each array:
//constructor
public function __construct() {
$this->arrCards = array();
$objCard = new Card("a", "heart");
array_push($this->arrCards, $objCard);
$objCard = new Card("2", "heart");
array_push($this->arrCards, $objCard);
$objCard = new Card("3", "heart");
blah blah continued...