RE: [PHP] Variable Next To Variable?

From: Date: Wed, 11 Jul 2001 18:22:48 +0000
Subject: RE: [PHP] Variable Next To Variable?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-57460@lists.php.net to get a copy of this message
personally, that's what i would do. dealing with arrays usually makes the code a lot cleaner and easier to follow than using awkward constructs like ${$C_Last}{$i} and besides, if you ever wanted to expand your code, you could easily pass the entire array to a function like so: children( $C_Last ); if you used individual variables, you could not do that in any easy or efficient way. > -----Original Message----- > From: Jeff Oien [mailto:jeff@webdesigns1.com] > Sent: Wednesday, July 11, 2001 1:29 PM > To: PHP > Subject: FW: [PHP] Variable Next To Variable? > > > What I'm doing is having a form page ask, "How many > children do you want to sign up?" Then it spits out form > fields for as many children as they asked for. So each > field has name="C_Last_Name$x" and $x in incremented > for each child. Should I make it name="C_Last_Name[$x]" ? > Jeff Oien > > > you should change the form field names to > > $Children_Last[1], $Children_Last[2] > > instead of hardcoding $Children_Last1 > > to make iteration thru the form easier > > and handling of the data easier... > > > > you can handle it all like this: > > > > $Number_Children = 5; > > $i = $Number_Children; > > while ($i--) { > > if (! $Children_Last[$i]) { > > // code > > } > > } > > > > > -----Original Message----- > > > From: Jeff Oien [mailto:jeff@webdesigns1.com] > > > Subject: [PHP] Variable Next To Variable? > > > > > > > > > Sorry if this has been brought up 100 times. > > > I want to do this: > > > > > > $y = "1"; > > > > > > while ($y <= "$Number_Children") { > > > if (!$C_Last_Name$y) { > > > error stuff; > > > $y++; > > > } > > > } > > > > > > The form submitting information to this code has field name like > > > C_Last_Name1 C_Last_Name2 depending on how many Children > > > are signing up for something. So I need $y to represent the number. > > > > > > Hope that makes sense. Thanks for any help. > > > Jeff Oien > > > > > > -- > > > PHP General Mailing List (http://www.php.net/) > > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > > For additional commands, e-mail: php-general-help@lists.php.net > > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > > For additional commands, e-mail: php-general-help@lists.php.net > > To contact the list administrators, e-mail: php-list-admin@lists.php.net > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#57460) next »