Re: Problem with Adding info into an array
| From: | CPT John W. Holmes | Date: | Mon, 21 Jul 2003 21:15:21 +0000 |
| Subject: | Re: Problem with Adding info into an array | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-156145@lists.php.net to get a copy of this message | ||
> I have 7 checkboxes, which make up the array information. I currently use
> implode to make the array, however that array only consists of the
> information that it checked.
>
> What I need to do now is make it so the array will always be 7 items, but
if
> there isnt a checkbox for the item, I want inserted to be a 0.
You could name the checkboxes such as
<input type="checkbox" name="item[0]" value="0">
<input type="checkbox" name="item[1]" value="1">
etc...
Then, since you know you have 7 boxes
for($x=0;$x<7;$x++)
{ $final_array[$x] = isset($_GET['item'][$x]) ? $_GET['item'][$x] : 0; }
or
$ar = array_fill(0,7,0);
$final_array = $_GET['item'] + $ar;
---John Holmes...