I’m trying to take two lines of code from an elseif statement and create a function that returns the parameters back to the parent function. It’s a simple card game that searches my $Cards array for a three of a kind. Here’s the original code:
elseif(count($Cards) == 3) {
$CardsNotOfValue = $this->_getCardsNotOfFaceValue($faceValue, $CardsGroupedByValues);
list($Kicker1, $Kicker2) = $this->_getSortedCards($CardsNotOfValue);
return new ThreeOfAKind(array_merge($Cards, array($Kicker1, $Kicker2)));
}
Thus far, my code looks like this:
function { if (count($Cards) == 3) {
**LINE 36** $Kicker = $this->kickerCards($faceValue, $CardsGroupedByValues); }
**LINE 55** public function kickerCards(array $kickers)
{
$CardsNotOfValue = $this->_getCardsNotOfFaceValue($faceValue, $CardsGroupedByValues);
return $this->_getSortedCards($CardsNotOfValue);
}
When I try to execute a four of a kind, I get the following error (I tried to highlight the lines in question above):
PHP Catchable fatal error: Argument 1 passed to BestHandIdentifier::kickerCards() must be an array, integer given, called in /home/dev/parameter2/BestHandIdentifier.php on line 36 and defined in /home/dev/parameter2/BestHandIdentifier.php on line 55
I’m having a bit of trouble understanding how to create ($faceValue, $CardsGroupedByValues) and pass an array for my new function to evaluate. Have I gone too far in the wrong direction to begin with?
Your function definition is:
So $kickers must be an array…
You are trying to call the function with:
Passing two arguments, the $faceValue which is an integer, 2nd argument is an array.
Your function definition should look like:
If I could elaborate further, making some assumptions.
My assumptions:
$twoOfHearts = array('value'=>2,'suit'=>'hearts');So here’s a possible implementation