Question : How To REMOVE VALUE from 'not checked checkboxes'

Hi experts,
I have this checkboxes on a submit form and each has a different 'name' :
<form method="post" action="">
Pick up your hobby :<br />
<input type="checkbox" name="hobby1" value="Fishing" />Fishing<br />
<input type="checkbox" name="hobby2" value="Reading" />Reading<br />
<input type="checkbox" name="hobby3" value="Sleeping" />Sleeping<br />
<input type="checkbox" name="hobby4" value="Eating" />Eating<br />
<input type="checkbox" name="hobby5" value="Swimming" />Swimming<br />
<input type="submit" name="submit" value="Submit" />
</form>

And part of the PHP Codes :
/* ############################# */
$amount = 5; // Amount of checkboxes
$prefix = "hobby"; // prefix for checkboxes (before numeric identifier)
$holder = array();

/* Arraying checkboxes result */
for ($i=1;$i<=$$amount;$i++){
$holder[] = (isset($_POST[$prefix.$i])) ? $_POST[$prefix.$i] : '';
}

$result = implode(",", $holder);
/* ############################# */
It works best if all options are checked ...
and, for example if just one option checked the result will goes like:
Fishing,,,,  OR  ,,,,Swimming

What I want to approach is removing the values from 'not checked checkboxes'.
So if only first and second checkboxes checked, the result should goes like :
Fishing,Reading
Or if only first options checked then the result goes :
Fishing
...it will be good too if you can remove the comma (,) from the last checked option.

IMPORTANT :
And I realy want to do this without interrupting the HTML codes.
I think I can find a correct solution if the checkboxes' name is name="hobby[]"
But having different naming for each checkbox makes me not able to find a solution.

Any help?  Is it possible to approach?

Answer : How To REMOVE VALUE from 'not checked checkboxes'

How about this:


<form method="post" action="">
Pick up your hobby :<br />
<input type="checkbox" name="hobby1" value="Fishing" />Fishing<br />
<input type="checkbox" name="hobby2" value="Reading" />Reading<br />
<input type="checkbox" name="hobby3" value="Sleeping" />Sleeping<br />
<input type="checkbox" name="hobby4" value="Eating" />Eating<br />
<input type="checkbox" name="hobby5" value="Swimming" />Swimming<br />
<input type="submit" name="submit" value="Submit" />
</form>
And part of the PHP Codes :
/* ############################# */
$amount = 5; // Amount of checkboxes
$prefix = "hobby"; // prefix for checkboxes (before numeric identifier)
$holder = array();
/* Arraying checkboxes result */
for ($i=1;$i<=$amount;$i++){
if($_POST[$prefix.$i] != ''){
 $holder[] = $_POST[$prefix.$i];
}
}
$result = implode(",", $holder);
Random Solutions  
 
programming4us programming4us