unset() un-appropriate ?
| From: | Ciprian Trofin | Date: | Mon, 13 Oct 2003 10:47:44 +0000 |
| Subject: | unset() un-appropriate ? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-165946@lists.php.net to get a copy of this message | ||
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
CODE:
$x = array($_POST['x1'],$_POST['x2'],$_POST['x3']);
do {
for ($i=0;$i < sizeof($x);$i++) {
$stop = 0;
if (!trim($x[$i])) {
$stop = 1;
unset($x[$i]);
break;
}
}
}
while ($stop>0);
For some reason, the code doesn't work (loops ad infinitum). But replacing
unset($x[$i]);
with
array_splice($indice, $i, 1);
it does.
Help!
--
Ciprian
> Remember that you are unique. Just like everyone else.