Jump to content

0rangeFish

New Members
  • Posts

    8
  • Joined

  • Last visited

0rangeFish's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. It returns an array with the three values that are in each card: if it's not blocked by other cards, the suit, and the card value. But just returning the index is better since I can't call a function in the heredoc, then I can just pull the card from the array and get it's info that way.
  2. I guess I actually need to return the index for the array instead of an array, but how would I return two numbers since it's for a 2D array?
  3. I'm using a here document for the html in my php page. In it I call a function to get the correct value to pass to the form and eventually to the next php page. I'm getting an error:Array to string conversion in. I'm not sure why, maybe I'm escaping the double quotes wrong? or do you need to do something special when the value being submitted is an array? This line is where the error is, the second table data in the first table row <td><input name="choice" type="radio" value=\"getCardValues($pyramid, 0,0)\" /></td> in here $output =<<< _HTML_ <!DOCTYPE html> <html> <head> <title>Pyramid Solitaire</title> </head> <body> <div class="main"> <h1>Rock Paper Scissors Game</h1> <form action="rps.php" method="post"> <input type="text" name="name"> <input type="hidden" name="past" value="0"> <table width="20%"> <tr> <td><img src="./images/cards/getCardFile($pyramid, 0,0)" width="100" height="100" /></td> <td><input name="choice" type="radio" value=\"getCardValues($pyramid, 0,0)\" /></td> </tr> for($i = 0; $i < 2; $i++) { <tr> <td><img src="./images/cards/getCardFile($pyramid, 1,$i)" width="100" height="100" /></td> <td><input name="choice" type="radio" value="getCardValues($pyramid, 1,$i)" /></td> </tr> } and so on... This is the function being called: function getCardValues($array, $row, $col) { $valuesHolder = array($array[$row][$col].getFace(), $array[$row][$col].getSuit()); return $valuesHolder; }
  4. Is it possible for a clickable image to pass to a php page? It can lead to a linked web page, so can it be like a submit button on a form and pass to the $_POST in php?
  5. Ah yes, that was it. I just assumed it was pass by reference because in other languages I code in arrays are by default. Thanks!
  6. I'm getting an error: Undefined offset: 1 in… I'm trying to display a 2D array after filling it. It displays fine if I echo it while it's being made, but after it is not working. I'm making a pyramid solitaire game and am trying to set up the pyramid of cards. There are 7 arrays, each with a set amount of cards in them. The first array only gets one cards while the last array gets seven. This makes it like a pyramid. All the indexes that don't get a card are set to 0. So it looks like this where the 1's are cards: 1 0 0 0 0 0 0 0 ​1 1 0 0 0 0 0 0 ​1 1 1 0 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 The display2Darray function is what is causing the error. Specifically this line: if($array[$i][$j] == 0) Heres my main code: <?php include_once "pyramidCard.php"; include_once "pyramidDeck.php"; $theDeck = new Deck(); $pyramid = array(array(), array(), array(), array(), array(), array(), array()); $size = 7; $theDeck->shuffleCards(); makePyramid($pyramid, $size, $theDeck); display2Darray($pyramid, $size); //************************ // FRUNCTIONS * //************************ function makePyramid($array, $size, $deck) { $row = 0; for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($j > $row) { $array[$i][$j] = 0; //echo ". <br>"; } else { $array[$i][$j] = $deck->dealCards(); //echo "this card is ".$array[$i][$j]->getFace()." of ".$array[$i][$j]->getSuit()."<br>"; } } $row++; } } function display2Darray($array, $size) { for($i = 0; $i < $size; $i++) { for($j = 0; $j < $size; $j++) { if($array[$i][$j] == 0) echo " "; else echo $array[$i][$j]->getFace()." of ".$array[$i][$j]->getSuit(); } echo "<br>"; } } ?>
  7. The url looks like this: h t t p :// localhost:8888/letterMath.php/?equation=1+2+3. The 1+2+3 is put into the variable $equation. But when I echo $equation is just gives me 1 2 3. (with the spaces replacing the +) This is the code used to put it out of the url: $equation = $_GET["equation"];
  8. I'm trying to get an equation from a user that types it in the url, ex) 1+2+3. I can get the 1,2,3 fine, but the + operator is no longer in the string. Same with the * and / operators. Is there a way to keep them as a string using $_GET?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.