Page 1 of 1
trouble with foreach
Posted: Thu Mar 03, 2011 6:47 pm
by someguyhere
Code: Select all
$designation_array = $_POST['designation'];
foreach ($designation_array as &$value) {
$value = '<li>' . $value . '</li>' . "\n";
}
$designation = '<ul>' . "\n" . $value . '</ul>' . "\n";
I can't tell why this is only returning one value. This comes from a series of check boxes, but it only stores the last one checked.
Re: trouble with foreach
Posted: Thu Mar 03, 2011 6:50 pm
by someguyhere
Solved it:
Code: Select all
$designation_array = $_POST['designation'];
foreach ($designation_array as &$value) {
$designation = $designation . '<li>' . $value . '</li>' . "\n";
}
$designation = '<ul>' . "\n" . $designation . '</ul>' . "\n";
Re: trouble with foreach
Posted: Fri Mar 04, 2011 5:41 am
by Darhazer
someguyhere wrote:Solved it:
Code: Select all
$designation_array = $_POST['designation'];
foreach ($designation_array as &$value) {
$designation = $designation . '<li>' . $value . '</li>' . "\n";
}
$designation = '<ul>' . "\n" . $designation . '</ul>' . "\n";
You can use
Code: Select all
$designation .= '<li>' . $value . '</li>' . "\n";
It's shorter.
Also, no need of & in front of the value, since you do not modify it (and you can run in another problems with the reference)