Re: [PHP] Problem with Adding info into an array
Phillip Blancher wrote: if($array[0]==) { $array[0]=0; } else { } if($array[1]==) { $array[1]=0; } else { } if($array[2]==) { $array[2]=0; } else { } if($array[3]==) { $array[3]=0; } else { } if($array[4]==) { $array[4]=0; } else { } if($array[5]==) { $array[5]=0; } else { } if($array[6]==) { $array[6]=0; } else { } But this just made the values of the array become blank. Any suggestions? Try if(!$array[0]) $array[0]='0'; -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Problem with Adding info into an array
In making an array: 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. Example item1[x] item2[x] item3[ ] item4[x] item5[ ] item6[x] item7[ ] would return = 1,2,0,4,0,6,0 instead of what it does now. 1,2,4,6 I tried placing in the lines before the implode command, saying that: if($array[0]==) { $array[0]=0; } else { } if($array[1]==) { $array[1]=0; } else { } if($array[2]==) { $array[2]=0; } else { } if($array[3]==) { $array[3]=0; } else { } if($array[4]==) { $array[4]=0; } else { } if($array[5]==) { $array[5]=0; } else { } if($array[6]==) { $array[6]=0; } else { } But this just made the values of the array become blank. Any suggestions? Thanks in advance, Phillip --- Outgoing mail is certified Virus Free. Checked by AVG anti-virus system (http://www.grisoft.com). Version: 6.0.501 / Virus Database: 299 - Release Date: 7/14/2003 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with Adding info into an array
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;$x7;$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... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php