Re: unset() un-appropriate ?
| From: | David Otton | Date: | Mon, 13 Oct 2003 11:01:59 +0000 |
| Subject: | Re: unset() un-appropriate ? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-165950@lists.php.net to get a copy of this message | ||
On Mon, 13 Oct 2003 12:47:44 +0200, you wrote:
>I have a form with 3 checkboxes x1,x2,x3. I want to build an array of
>values from the checked boxes; I choosed the following approach:
>1. build an array with all values
>2. eliminate from array the "" values using unset
>
>For some reason, the code doesn't work (loops ad infinitum). But replacing
Turning your error-reporting level up might give you a hint.
I've no idea what you're trying to accomplish, but I would guess you're
trying for this:
<?
$x = array('a', '', 'c', 'd');
$stop = FALSE; // moved the creation of the flag outside the loop
do
{
for ($i = 0; $i < sizeof($x); $i++)
{
if (trim ($x[$i]) == FALSE) {
$stop = TRUE;
unset ($x[$i]);
break;
}
}
} while ($stop == FALSE); // check this line against your code
?>
infinite loops seem to be part of the design. Maybe this would be better for
you?
<?
$x = array('a', '', 'c', 'd');
for ($i = 0; $i < sizeof ($x); $i++)
{
if (trim ($x[$i]) == FALSE) {
unset ($x[$i]);
}
}
print_r ($x);
?>