Contact Us Forum Rules Search Archive
WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

Web Programming Discussion Forum Working with an API? Developing a plugin? Writing a Mod or script for your favorite blog, Web 2.0 site or Forum? Welcome.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 09-12-2004, 05:25 PM
WebProWorld Pro
 

Join Date: Jul 2003
Location: Canada
Posts: 268
ackerley1 RepRank 0
Default Adding to Arrays

<Using PHP>
I am trying to create an array that adds different variables to it if they are selected on a form via checkboxes.

IE:
FORM
[] option1 [] option2 [] option3

suppose that option1 and option 3 are checked

I have this at the start of my form processing page:
if (isset($option1))
{
$option1 = OP_ONE;
$option1_SLCT = OP_ONE;
$option = array ($option1);
}
if (isset($option2))
{
$option2 = OP_TWO;
$option2_SLCT = OP_TWO;
$option = array ($option2);
}
if (isset($option3))
{
$option3 = OP_THREE;
$option3_SLCT = OP_THREE;
$option = array ($option3);
}

Now in the above, this will set the array only to the last one select. In this case option3 is the only value in the array. How do I add multiple variables to the $option array in the above set up?

I have tried
$option .= $option2
and
$option .+ $option2

I need the variables as stand alone variables (the first two lines of the if statement) in other parts of the processing as well, so I cannot just set up the form to put them all in a variable using name="option[]" value="option1"> etc.

Not sure what else to try.

Any ideas or suggestions?

Thanks

Rob
__________________
Rob
Reply With Quote
  #2 (permalink)  
Old 09-13-2004, 02:01 AM
Easywebdev's Avatar
WebProWorld Veteran
 

Join Date: Apr 2004
Posts: 328
Easywebdev RepRank 1
Default

to add to an array or combine arrays.

$option = array();
$option += $option1;
$option += $option2;
$option += $option3;

Your code should read
$option = array();
if (isset($option1))
{
$option1 = OP_ONE;
$option1_SLCT = OP_ONE;
$option += $option1;
}
if (isset($option2))
{
$option2 = OP_TWO;
$option2_SLCT = OP_TWO;
$option += $option2;
}
if (isset($option3))
{
$option3 = OP_THREE;
$option3_SLCT = OP_THREE;
$option += $option3;
}

Quote:
Now in the above, this will set the array only to the last one select. In this case option3 is the only value in the array.
This is because you are not adding to the array rather creating a new $option array containing $option3.

HTH
__________________
"I have not failed. I have found 10,000 ways that don't work" - Thomas Edison.
"The secret to creativity is knowing how to hide your sources" - Albert Einstein.
Reply With Quote
  #3 (permalink)  
Old 09-14-2004, 10:36 AM
WebProWorld Pro
 

Join Date: Jul 2003
Location: Canada
Posts: 268
ackerley1 RepRank 0
Default

I have tried this, but it gives me this error:

Fatal error: Unsupported operand types - Line 7

The option 1 += line.

Would this have anything to do with it being a string and not numbers?

Any other suggestions?

Thanks

Rob
__________________
Rob
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Web Programming Discussion Forum
Tags: ,



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Search Engine Optimization by vBSEO 3.2.0