note 71048 deleted from language.variables by bobby
| From: | bobby@php.net | Date: | Mon, 13 Nov 2006 22:56:57 +0000 |
| Subject: | note 71048 deleted from language.variables by bobby | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-119690@lists.php.net to get a copy of this message | ||
Note Submitter: jphansen at uga dot edu
----
I had the issue of numerous HTML form checkboxes under separate groupings and not wanting to
evaluate each checkbox individually. PHP's variable concatenation allowed me to vastly simplify
this process by defining each checkbox grouping in a uniform name followed by incremental integer,
then executing this code:
<?
$groups = array(27 => 'infants', 28 => 'toddlers', 41 =>
'teens');
foreach ($groups as $count => $name)
for ($i = 0; $i < $count; $i++)
if (${$name . $i})
${"total_" . $name} .= ${$name . $i} . ", ";
?>
From here you can store $total_* variable(s) and retrieve them exploding on a comma delimiter.