Array help

I am working on a simple array. I have a suite of cards (13 images named card1, card2, card3, etc) and I need to print five of them at a time showing random cards.

The below code doesn’t work and need a set of eyes to spot an error or maybe the whole this is an error?

[php]<?php

$card[1] = rand(1,13);
$card[2] = rand(1,13);
$card[3] = rand(1,13);
$card[4] = rand(1,13);
$card[5] = rand(1,13);

for ($i = 1; $i < 6; $i++){
print ;
}
?>[/php]

Two ways:

[php]for ($x=0; $x<=5; $x++)
{
echo “<img src = “card”.(rand(1,13)).”.jpg" />";
}[/php]

[php] $card = range(1, 13);

$k = array_rand($card, 5);

foreach ($k as $k => $v)
{
echo “<img src = “card$v.jpg” />”;
}[/php]

Hey thanks!

Sponsor our Newsletter | Privacy Policy | Terms of Service