0rangeFish Posted December 11, 2014 Share Posted December 11, 2014 (edited) 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; } Edited December 11, 2014 by 0rangeFish Quote Link to comment Share on other sites More sharing options...
requinix Posted December 11, 2014 Share Posted December 11, 2014 PHP has no idea you're trying to call a function named "getCardValues". As far as it knows, there's a whole bunch of text and then suddenly $pyramid and then a lot more text after. It's not going to try to guess what you want. You can use a variable and that's it. So put your getCardValues() stuff into a variable, do the same for the others, and insert those variables where you want the values to appear. Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 11, 2014 Share Posted December 11, 2014 (edited) On top of what was said above you cant place PHP code with a heredoc statement. Before the for loop you will need to close the heredoc statement and then inside the for loop you can concatenate the string to the $output variable using the concatenation assignment operator .= Example $output = <<<_HTML ... HTML; // close heredoc statement // start for loop for( ... ) { // concatenate html to $output $output .= <<<_HTML <tr> ... html for row ... </tr> HTML; } $output .= <<<_HTML ... rest of html for the page ... _HTML_; Now you may find you'll get the same error after you have done what has been suggested. This is because the getCardValues() function is returning an array. PHP wont know what you want to do with that. What should be returned from that function? Edited December 11, 2014 by Ch0cu3r Quote Link to comment Share on other sites More sharing options...
0rangeFish Posted December 11, 2014 Author Share Posted December 11, 2014 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? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted December 11, 2014 Share Posted December 11, 2014 You are already passing the indexes to the getCardValues function when you are calling it. So what purpose does this function serve?. Quote Link to comment Share on other sites More sharing options...
0rangeFish Posted December 11, 2014 Author Share Posted December 11, 2014 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.