chrisk_47 Posted November 1, 2007 Share Posted November 1, 2007 I have the following code for looping through a checkbox array: if (!empty($_POST['Breakfast'])) { echo "Breakfast"; foreach ($_POST['Breakfast'] as $checkbox) { echo $checkbox; } } //example output Breakfast Bagels Doughnuts Fruit The above works great for printing out the selected choices to the page, but how can I get the selected choices into a string variable for use later in my script (for instance I want to include it in a confirmation email)? Link to comment https://forums.phpfreaks.com/topic/75655-get-value-from-checkbox-group/ Share on other sites More sharing options...
GingerRobot Posted November 1, 2007 Share Posted November 1, 2007 You could just implode() the array - perhaps using a comma as the 'glue': <?php if (!empty($_POST['Breakfast'])) { $breakfast = implode(',',$_POST['Breakfast']); echo 'Breakfast requirements: '.$breakfast } ?> Link to comment https://forums.phpfreaks.com/topic/75655-get-value-from-checkbox-group/#findComment-382847 Share on other sites More sharing options...
chrisk_47 Posted November 1, 2007 Author Share Posted November 1, 2007 Excellent Ben, just what I was looking for. Thank you, Chris Link to comment https://forums.phpfreaks.com/topic/75655-get-value-from-checkbox-group/#findComment-382885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.