beatroute Posted February 9, 2007 Share Posted February 9, 2007 Hi there, first off i'd like to congratulate all those responsible for the site as it has provided me with great help at understanding the basics of PHP. However, i've encountered a problem no else seems to have (as far as i've looked) and would greatly appreciate any form of help. Basically, i'm trying to put together a card game script (54 cards), which i'll simplify here with only 6 cards. //First i define the cards, $pack = array('1','2','3','4','5','6'); //Then shuffle them, shuffle($pack); //Then hand them out for ($i = 0; $i < 6; $i += 2) { $j = $i + 1; //to a first, $playera[] = &$pack[$i]; //then a second player. $playerb[] = &$pack[$j]; } //I then sort both packs, sort($playera); sort($playerb); //and i try to get them to show up as '.gif's echo "Player A's cards are:<br>"; for ($i = 0; $i < 3; $i++) { echo "<img src='$playera[$i].gif'>"; } echo "Player B's cards are:<br>"; for ($i = 0; $i < 3; $i++) { echo "<img src='$playerb[$i].gif'>"; } My problem is i get the "Image not found" logo (small red cross in box) for each card. When i click on any of these images' properties i see 'Array.gif' and not '1.gif' or '5.gif', etc.... i've tried other echoes: "<img src='" . $playera[$i] . ".gif'>"; AND $card = $playera[$i]; "<img src='{$card}.gif'>"; AND foreach ($playera as $playeras) { echo "<img src='$playeras.gif'>"; none of which have worked so far. If someone could please point out what i'm doing wrong i would be very grateful. Link to comment https://forums.phpfreaks.com/topic/37746-trouble-retrieving-values-from-array/ Share on other sites More sharing options...
JasonLewis Posted February 9, 2007 Share Posted February 9, 2007 are you sure? i've copied and pasted that code, and even though it wont work for me, i right click and view the properties. they show 1, 2, 3 etc... Link to comment https://forums.phpfreaks.com/topic/37746-trouble-retrieving-values-from-array/#findComment-180567 Share on other sites More sharing options...
beatroute Posted February 9, 2007 Author Share Posted February 9, 2007 Thanks for the reply ProjectFear, i've looked through the code again and couldnt see any errors. Here's the whole thing: <html><head></head> <body> <?php $cards = array('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29' ,'30','31','32','33','34','35','36','37','38','39','40','41','42','43','44','45','46','47','48','49','50','51','52','53','54'); shuffle($cards); for ($i = 0; $i < 54; $i++) { $pack[] = array($cards[$i]); } for ($i = 0; $i < 54; $i += 2) { $j = $i + 1; $playa[] = &$pack[$i]; $playb[] = &$pack[$j]; } echo "<br><h1>Player 1's sorted cards:<br></h1>"; sort($playa); for ($i = 0; $i < 27; $i++) { echo "<img src='img/$playa[$i].gif'>"; } echo "<br><h1>Player 2's sorted cards:<br></h1>"; sort($playb); for ($i = 0; $i < 27; $i++) { echo "<img src='img/$playb[$i].gif'>"; } ?> </body> </html> Basically it's the same code with more cards, do you see what could cause the "array.gif" error? Thanks again. Link to comment https://forums.phpfreaks.com/topic/37746-trouble-retrieving-values-from-array/#findComment-180574 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.