Just to add a bit to this thread.  The following can be 
bad:

  <input type="checkbox" name="foo[]">
  <input type="checkbox" name="foo[]">
  <input type="checkbox" name="foo[]">

A potential gotcha.  Be sure to either define an array key 
and/or a value.  Because assuming all the above are checked, 
the following will result:

   $foo = array('on','on','on');

If two are checked, then we'll get:

   $foo = array('on','on');

Doesn't matter which two were checked :)  And as you 
guessed/know, if no value is set, 'on' will be the value as 
'on' is the default value for checkboxes.  And, if something 
is not checked, no value is passed at all.

That said, either do one of the following formats, feel 
free to mix and match, it doesn't matter.  Just know 
what you're doing :)

  <input type="checkbox" name="foo[]" value="something">

  <input type="checkbox" name="foo[key]">

  <input type="checkbox" name="foo[key]" value="something">

Then work with array foo as you see fit.  Be sure to read 
that faq (link posted earlier), it covers this.  Regarding 
your words, you guessed right, the second wrote over 
the first.  PHP requires [brackets] for arrays in forms.

And on a related note, a good way to "debug" arrays 
is through using print_r or var_dump.  You said you 
use PHP3, so use var_dump().

  var_dump($HTTP_POST_VARS);

It's been so long since PHP3 was cool, I barely remember 
how it works.  Maybe just try phpinfo() :)  But if 
track_vars are on, predefined php variables such 
as $HTTP_POST_VARS will exist.  And $foo should exist, 
anyway, enough on that.  Try hard to get PHP4 :)

  http://jp.php.net/manual/ja/language.variables.predefined.php

That page is in Japanese, hope it makes sense to you 
as it sure doesn't to me :)

Regards,
Philip Olson


On Sat, 19 Jan 2002, Steven Maroney wrote:

> 
> I hope im on the right track Cause im jumping in on this post.
> 
>  $MYCHK isn't an array cause you aren't using array syntax or simply left
> out the brackets.
> 
>  try:
> 
>  ( for the checkboxes )
>  <INPUT TYPE="CHECKBOX" NAME="MYCHK[]" VALUE="A">
>  <INPUT TYPE="CHECKBOX" NAME="MYCHK[]" VALUE="B">
> 
> I have done this 100's of times.
> 
> 
> Hope this helps,
> Steve
> 
> On Sat, 19 Jan 2002, K.Tomono wrote:
> 
> > Yes, I think too, it's better way to use an array rather than a dynamic
> >  name of the variable.
> > 
> > I thought that the first question means how to use a dynamic variable.
> > 
> > By the way,
> > 
> > > little array propaganda, jic  :)  Arrays work great in forms too!
> > >
> > >   http://www.php.net/manual/en/faq.html.php#AEN73718
> > 
> > Does this technique work fine on the version 3.0.14 later to 3.0.18
> >  of PHP? (Not PHP4)
> > 
> > I tried an array in forms simply like below in the other day,
> >  but this didn't work fine...
> > 
> > ( for the checkboxes )
> > <INPUT TYPE="CHECKBOX" NAME="MYCHK" VALUE="A">
> > <INPUT TYPE="CHECKBOX" NAME="MYCHK" VALUE="B">
> > 
> > Unfortunately, I had thought that it could be got as an array,
> >  but variable $MYCHK is overwritten by the last value "B" always.
> > 
> > (To mention about java servlet, this value could be retrieved by
> >  the syntax as below.
> > 
> > (HttpServletRequest)request.getParameterValues("MYCHK")[0]
> > 
> > off course, such a syntax occurs an error on PHP. ;D)
> > 
> > --
> > Well, I'll try the technique you mentioned.
> > Your offering is very appreciated.
> > Thank you!
> > :-]
> > 
> > ps.
> > execute me for my english...
> > 
> > ---------------
> > K.Tomono
> > 
> > 
> > > -----Original Message-----
> > > From: Philip Olson [mailto:[EMAIL PROTECTED]]
> > > Sent: Saturday, January 19, 2002 2:30 PM
> > > To: —F–쌤Œá
> > > Cc: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > > Subject: Re: [PHP] Variable Problem
> > >
> > >
> > >
> > > > How do I combine the following so it is treated as one variable.
> > >
> > > It's a good question, but why?  Most likely an array will
> > > work best for
> > > this job, arrays are good:
> > >
> > >   http://www.php.net/manual/en/language.types.array.php
> > >
> > > The man page on foreach is nice too, and has many examples
> > > which include
> > > while/list alternatives:
> > >
> > >   http://www.php.net/manual/en/control-structures.foreach.php
> > >
> > > Your question was answered below but I couldn't resist throwing in a
> > > little array propaganda, jic  :)  Arrays work great in forms too!
> > >
> > >   http://www.php.net/manual/en/faq.html.php#AEN73718
> > >
> > > Regards,
> > > Philip Olson
> > >
> > >
> > > > >
> > > > >$i=10
> > > > >$result$i="test";
> > > > >
> > > > >I want this to be:
> > > > >
> > > > >$result10="test";
> > > > >
> > > > >$i changes so I cannot just put in 10 instead of I.
> > > > >anybody know how i can do that?
> > > > >
> > > > >TIA
> > > > >Randy
> > > >
> > > > How about the below.
> > > >
> > > > <?
> > > > $i=10;
> > > > ${"result$i"}="test";
> > > > echo $result10;
> > > > ?>
> > > >
> > > > or
> > > >
> > > > <?
> > > > $i=10;
> > > > ${'result'.$i}="test";
> > > > echo $result10;
> > > > ?>
> > > >
> > > > Cheers :-)
> > > > -----------------------------------
> > > > K.Tomono
> > >
> > 
> > 
> > -- 
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
> > To contact the list administrators, e-mail: [EMAIL PROTECTED]
> > 
> > 
> 
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
> 



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to