koushikgattu Posted December 4, 2007 Share Posted December 4, 2007 Hi, i am a beginner. I am having problem while printing the check box arrays and with the joining of arrays. here is the sample code: <?php $retval = '<form name="myform action="post"><input type="checkbox" name="array1[]" value="elem1" checked >feed1</label><br/>'; $retval .= '<input type="checkbox" name="array1[]" value="elem2" checked >feed2</label><br/>'; $retval .= '<input type="checkbox" name="array2[]" value="elem3" checked >feed3</label><br/>'; $retval .= '<input type="checkbox" name="array3[]" value="elem4" checked >feed4</label></form>'; echo $_POST['array1[]']; print_r($_POST['array1[]']); //print_r($array2); //print_r($array3); ?> I am trying to print the array1[], array2[], and array3[] and also put the elements of these arrays into one array(with out override).Can somebody help me with this? Thanks Link to comment https://forums.phpfreaks.com/topic/80166-check-box-arrays/ Share on other sites More sharing options...
freakstyle Posted December 4, 2007 Share Posted December 4, 2007 Hey there, to print out the post you just use: <?php print_r($_POST); // to merge them: $MergedArray = array_merge( $_POST['array1'], $_POST['array2']); good luck, http://us.php.net/array_merge Link to comment https://forums.phpfreaks.com/topic/80166-check-box-arrays/#findComment-406310 Share on other sites More sharing options...
mr_mind Posted December 4, 2007 Share Posted December 4, 2007 try this. i think it is what you want: <?php if($_POST['submit']) { $array = $_POST['array']; print 'You have selected these items:<ul>'; foreach($array as $item) { print $item . '<br />'; } print '</ul>'; } else { print '<form name=' . $_SERVER['PHP_SELF'] . ' method=post>'; print '<label for=item1>Item 1:</label><input type=checkbox name=array[] value=item1 checked><br />'; print '<label for=item1>Item 2:</label><input type=checkbox name=array[] value=item2 checked><br />'; print '<label for=item1>Item 3:</label><input type=checkbox name=array[] value=item3 checked><br />'; print '<label for=item1>Item 4:</label><input type=checkbox name=array[] value=item4 checked><br />'; print '<label for=item1>Item 5:</label><input type=checkbox name=array[] value=item5 checked><br />'; print '<input type=submit name=submit value=Submit />'; } ?> Link to comment https://forums.phpfreaks.com/topic/80166-check-box-arrays/#findComment-406312 Share on other sites More sharing options...
koushikgattu Posted December 4, 2007 Author Share Posted December 4, 2007 Thank you for your replies. But i am just trying to print the arrays (array1 ,array2 etc) and concatenating them into one array(before clicking the submit button). Is there any way i could do that? thanks Link to comment https://forums.phpfreaks.com/topic/80166-check-box-arrays/#findComment-406338 Share on other sites More sharing options...
PHP_PhREEEk Posted December 4, 2007 Share Posted December 4, 2007 <?php $retval = '<form name="myform action="post"><input type="checkbox" name="array1[]" value="elem1" checked >feed1</label> '; $retval .= '<input type="checkbox" name="array1[]" value="elem2" checked >feed2</label> '; $retval .= '<input type="checkbox" name="array1[]" value="elem3" checked >feed3</label> '; $retval .= '<input type="checkbox" name="array1[]" value="elem4" checked >feed4</label></form>'; //echo $_POST['array1[]']; print_r($_POST['array1']); //print_r($array2); //print_r($array3); ?> Putting all the values into just array1 will give you 3 elements after POSTing $_POST['array1'][0] = elem2 $_POST['array1'][1] = elem3 $_POST['array1'][2] = elem4 No merging necessary... PhREEEk Link to comment https://forums.phpfreaks.com/topic/80166-check-box-arrays/#findComment-406348 Share on other sites More sharing options...
koushikgattu Posted December 5, 2007 Author Share Posted December 5, 2007 Thank you so much Link to comment https://forums.phpfreaks.com/topic/80166-check-box-arrays/#findComment-407042 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.