Jump to content

[SOLVED] array help part 2 ...


imarockstar

Recommended Posts

Thanks for the help with the last post ... I know understand how that works !!!!

 

This is my second question about arrays ... So I have a form that groups 3 input boxes together and returns the POST data into an array ...

 

as follows :

 

<?php
if ( $_POST['submit'] )
{
   foreach($_POST['group1'] as $key=>$value){
      echo "$key: $value<br />";
   }      
}
?>



<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" ?>



<!-- group 1 -->
field 1 : <input name="group1[text1]" size="20" > <br>
field 2 : <input name="group1[text2]" size="20" > <br>
field 3 : <input name="group1[text3]" size="20" > <br><br>

<input type="submit" name="submit" value="test">

</form>

 

the above works great !!!!

 

What i need to do is ad 2 more groups of questions ... so that I can have 3 arrays ... each with the values of the groups of questions .. but i am nore sure how to modify the FOR EACH statement to allow this to happen ...

 

as follows :

 

<?php
if ( $_POST['submit'] )
{
   foreach($_POST['group1'] as $key=>$value){
      echo "$key: $value<br />";
   }      
}
?>



<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" ?>



<!-- group 1 -->
field 1 : <input name="group1[text1]" size="20" > <br>
field 2 : <input name="group1[text2]" size="20" > <br>
field 3 : <input name="group1[text3]" size="20" > <br><br>


<!-- group 2 -->
field 4 : <input name="group2[text1]" size="20" > <br>
field 5 : <input name="group2[text2]" size="20" > <br>
field 6 : <input name="group2[text3]" size="20" > <br><br>

<!-- group 3 -->
field 7 : <input name="group3[text1]" size="20" > <br>
field 8 : <input name="group3[text2]" size="20" > <br>
field 9 : <input name="group3[text3]" size="20" > <br><br>




<input type="submit" name="submit" value="test">

</form>

 

 

Link to comment
https://forums.phpfreaks.com/topic/166109-solved-array-help-part-2/
Share on other sites

hmmz try this?

 

not sure what'll happen :D

 

 

<?php

if ( $_POST['submit'] ){

 

for($i=1;$i<4;$i++){

 

foreach($_POST["group$i"] as $key=>$val){

 

echo "$key: $val<br />";

 

}//end foreach

 

}//end for

     

}//end if

?>

 

lemme know ;)

 

[/php

Archived

This topic is now archived and is closed to further replies.

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