Jump to content

[SOLVED] From Post to Array?


jandrews3

Recommended Posts

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.