jandrews3 Posted August 16, 2009 Share Posted August 16, 2009 I am receiving from a form of 1-50, variables answer1 through answer50 for example. There is a way to initiate some kind of temporary variable like below so that they can essentially be treated as an array, but I do not know how. If someone could tell me what would get the code below to work, then I know I could incorporate the concept into my page. Thank you. $count = 0; $max = 49; while ($count <= $max){ print "You typed: ".$answer.$count."<br>"; print "You were asked: ".$new.$count."<br>"; print "The answer was: ".$ans.$count."<br>"; $count++; } Link to comment https://forums.phpfreaks.com/topic/170511-solved-from-post-to-array/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 16, 2009 Share Posted August 16, 2009 You should use an array in your form - http://us.php.net/manual/en/faq.html.php#faq.html.arrays Use array index names that are the entry number - <input name="answer[1]" /> <input name="answer[2]" /> <input name="answer[3]" /> ... Link to comment https://forums.phpfreaks.com/topic/170511-solved-from-post-to-array/#findComment-899456 Share on other sites More sharing options...
steve.davis Posted August 16, 2009 Share Posted August 16, 2009 Try this... $MyForm = str_replace(array("-","!",".","?","\n","\r","(",")",),' ',$_POST['MyForm']); $MyTempArray = explode(' ', $MyForm); print_r ($MyTempArray); Link to comment https://forums.phpfreaks.com/topic/170511-solved-from-post-to-array/#findComment-899638 Share on other sites More sharing options...
Andy-H Posted August 16, 2009 Share Posted August 16, 2009 $arr = range(1,50); forEach($arr as $v) { echo "\t" . '<input type="text" name="answer[' . $v . ']" size="30" ><br >' . "\n\r"; } // when data is posted forEach($_POST['answer'] as $k => $v) { echo "\t\t" . 'Q' . $k . '. You answered: ' . stripslashes(HTMLentities($v, ENT_QUOTES)) . '<br ><br >' . "\n\r"; } Link to comment https://forums.phpfreaks.com/topic/170511-solved-from-post-to-array/#findComment-899661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.