开发者

Help with images and arrays

开发者 https://www.devze.com 2023-01-21 13:56 出处:网络
I have an assignment for school call Poker game. I have to deal a random card of five using HTML. I also need to have an array to deal the cards. My main question is can you have images in an array an

I have an assignment for school call Poker game. I have to deal a random card of five using HTML. I also need to have an array to deal the cards. My main question is can you have images in an array and if so how can it be done? I tried this method:

$my_array = array(img src="2Spade.gif", img src="2Club.gif") 

but this is incorrect! Can anyone give me suggestions on how to build the program provide sample code for m开发者_如何学运维e to try?


What you want to have in the array is the string which holds the location of the image, not the image itself.

$cardArray = array("2Spade.gif", "2Club.gif");


If you truly wanted to have the code source in the array you could do this:

$my_array = array("img src=\"2Spade.gif\"", "img src=\"2Club.gif\"");

Then to use it you'd do something like:

if( is_array( $my_array ) && count( $my_array ) > 0 ) {
    foreach( $my_array as $card ) {
        echo '<' . $card . ' />';
    }
}

But I think Sam Dufel's answer is the better way to create and store the information in an array ...

0

精彩评论

暂无评论...
验证码 换一张
取 消