0

I have my root folder, and within my root folder is a folder named images. Within the images folder is 4 subfolders, each named after a Suit of cards. Within each Suit folder, I have 13 pictures named after cards. Ace.jpg, Two.jpg, etc. Within my Code, I declare each suit and card as a variable.

/*Array used to select a random number*/
$CardNumber = array();
$CardNumber[0]="Ace";
$CardNumber[1]="Two";
$CardNumber[2]="Three";
$CardNumber[3]="Four";
$CardNumber[4]="Five";
$CardNumber[5]="Six";
$CardNumber[6]="Seven";
$CardNumber[7]="Eight";
$CardNumber[8]="Nine";
$CardNumber[9]="Ten";
$CardNumber[10]="Jack";
$CardNumber[11]="Queen";
$CardNumber[12]="King";

/*Array used to select a random suit.*/
$CardSuit = array();
$CardSuit[0]="Clubs";
$CardSuit[1]="Diamonds";
$CardSuit[2]="Hearts";
$CardSuit[3]="Spades";

After a player picks a Card and a Suit, is there anyway to display the card he chose?

E.G. If You picked the 5 of Clubs, it would display the picture named Five.jpg from the Clubs folder?

2 Answers 2

4

As far as I understand you just need to create an image tag with the src pointing to the right file in the right directory...

$suit = 'Hearts';
$card = 'Queen';
printf('<img src="%s/%s.jpg">', $suit, $card);
Sign up to request clarification or add additional context in comments.

Comments

0

I guess you could do the following if you want to pick a random card

$CNkey = array_rand($CardNumber);
$CSKey = array_rand($CardSuit);
$randomCardNumber = $CardNumber[$CNKey];
$randomCardSuit = $CardSuit[$CSKey];   
$image = '/images/' . $randomCardSuit . '/' . $randomCardNumber . '.jpg'; // or any other image extensions

echo '<img src="' . $image . '">';

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.