[PHP] Variables within variable names

2002-05-02 Thread Jackson Miller

I want to do something along the lines of:

$type = basic;
$$type_user = jaxn;
echo $basic_user;

and have the output be jaxn.

I have tried everything I can think of, and I have looked in all my
books.

I know how to:

$type = basic;
$$type = jaxn;
echo $basic;

but this won't do what I need.  I need the name of the variable to be a
variable plus some.

I can probably reach my goals using arrays, but I just thought I would
ask first.

-Jackson


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Variables within variable names

2002-05-02 Thread Jason Wong

On Friday 03 May 2002 02:43, Jackson Miller wrote:
 I want to do something along the lines of:

 $type = basic;
 $$type_user = jaxn;
 echo $basic_user;

 and have the output be jaxn.

 I have tried everything I can think of, and I have looked in all my
 books.

 I know how to:

 $type = basic;
 $$type = jaxn;
 echo $basic;

 but this won't do what I need.  I need the name of the variable to be a
 variable plus some.

 I can probably reach my goals using arrays, but I just thought I would
 ask first.

Rather than tying yourself in knots, plus the fact that code using variable 
variables are mostly harder to debug, you are strongly advised to use arrays.

-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design  Hosting * Internet  Intranet Applications Development *

/*
Your love life will be... interesting.
*/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Variables in variable names

2001-05-09 Thread seriousj

Hello,

 I need some help (newbie).

I have some variable names with the form:
$name_1
$name_2
$name_3
$name_4...

I want to access them by doing something like this:
$i=0
$name_$i

This doesn't work, how do I include another variable in the name of a
variable?.

Cheers
John





-- 
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]




RE: [PHP] Variables in variable names

2001-05-09 Thread Taylor, Stewart

Maybe an array would be more appropriate.
e.g.

$name[$i] = 
.
.




-Stewart
-Original Message-
From: seriousj [mailto:[EMAIL PROTECTED]]
Sent: 09 May 2001 12:09
To: [EMAIL PROTECTED]
Subject: [PHP] Variables in variable names


Hello,

 I need some help (newbie).

I have some variable names with the form:
$name_1
$name_2
$name_3
$name_4...

I want to access them by doing something like this:
$i=0
$name_$i

This doesn't work, how do I include another variable in the name of a
variable?.

Cheers
John





-- 
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]




Re: [PHP] Variables in variable names

2001-05-09 Thread seriousj

The info is stored in the variables intitally by information entered by a
user on a webpage, can you have the browser store the info in an array and
have it passed by a form post  command?

Taylor, Stewart [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Maybe an array would be more appropriate.
 e.g.

 $name[$i] =
 .
 .




 -Stewart
 -Original Message-
 From: seriousj [mailto:[EMAIL PROTECTED]]
 Sent: 09 May 2001 12:09
 To: [EMAIL PROTECTED]
 Subject: [PHP] Variables in variable names


 Hello,

  I need some help (newbie).

 I have some variable names with the form:
 $name_1
 $name_2
 $name_3
 $name_4...

 I want to access them by doing something like this:
 $i=0
 $name_$i

 This doesn't work, how do I include another variable in the name of a
 variable?.

 Cheers
 John





 --
 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]




RE: [PHP] Variables in variable names

2001-05-09 Thread Ralph Guzman

As an alternative you can use associative arrays

$i = 0;
$i = 1;
$i = 2;
$i = 3;

$name[$i];



-Original Message-
From: seriousj [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 09, 2001 4:09 AM
To: [EMAIL PROTECTED]
Subject: [PHP] Variables in variable names

Hello,

 I need some help (newbie).

I have some variable names with the form:
$name_1
$name_2
$name_3
$name_4...

I want to access them by doing something like this:
$i=0
$name_$i

This doesn't work, how do I include another variable in the name of a
variable?.

Cheers
John





--
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]




RE: [PHP] Variables in variable names

2001-05-09 Thread Taylor, Stewart

Yes!

Add '[]' to the end of the name.
This will inform php that all fields with that name should be put into an
array after submission.

e.g.
FORM...
INPUT TYPE=TEXT NAME=name[]
INPUT TYPE=TEXT NAME=name[]
INPUT TYPE=TEXT NAME=name[]
...


After submit php will have created an array called $name with 3 entries.


-Stewart


-Original Message-
From: seriousj [mailto:[EMAIL PROTECTED]]
Sent: 09 May 2001 12:20
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Variables in variable names


The info is stored in the variables intitally by information entered by a
user on a webpage, can you have the browser store the info in an array and
have it passed by a form post  command?

Taylor, Stewart [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 Maybe an array would be more appropriate.
 e.g.

 $name[$i] =
 .
 .




 -Stewart
 -Original Message-
 From: seriousj [mailto:[EMAIL PROTECTED]]
 Sent: 09 May 2001 12:09
 To: [EMAIL PROTECTED]
 Subject: [PHP] Variables in variable names


 Hello,

  I need some help (newbie).

 I have some variable names with the form:
 $name_1
 $name_2
 $name_3
 $name_4...

 I want to access them by doing something like this:
 $i=0
 $name_$i

 This doesn't work, how do I include another variable in the name of a
 variable?.

 Cheers
 John





 --
 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]

-- 
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]




Re: [PHP] Variables in variable names

2001-05-09 Thread seriousj

Thanks, that worked great!

John



-- 
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]




Re: [PHP] Variables in variable names

2001-05-09 Thread heinisch

At 09.05.01  23:08, you wrote:
Hello,
  I need some help (newbie).
I have some variable names with the form:
$name_1
$name_2
$name_3
$name_4...
I want to access them by doing something like this:
$i=0
$name_$i
This doesn't work, how do I include another variable in the name of a
variable?.
What you´re looking for is variable variables, Try this:
for ($i=0; $i  $max_var_count;$i++)
{
 $tmp=name_.$i;
 $show_var_name_content=$$tmp;
}
THT Oliver


--
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]




Re[2]: [PHP] Variables in variable names

2001-05-09 Thread Adaran (Marc E. Brinkmann)

Hi seriousj,

Wednesday, May 09, 2001, 1:19:55 PM, you wrote:

seriousj The info is stored in the variables intitally by information entered by a
seriousj user on a webpage, can you have the browser store the info in an array and
seriousj have it passed by a form post  command?

Try

input type=text name=name[0]
input type=text name=name[1]
...

or even try
input type=text name=name[]
input type=text name=name[]

This should AFAIK result in an Array, but I'm not sure if empty fields are put
in.

---
EnjoY,
 Adaran ([EMAIL PROTECTED])
   check http://www.adaran.net



-- 
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]




RE: Re[2]: [PHP] Variables in variable names

2001-05-09 Thread Matt Schroebel

 or even try
 input type=text name=name[]
 input type=text name=name[]
 
 This should AFAIK result in an Array, but I'm not sure if 
 empty fields are put in.

You will get the empty fields except for checkboxes.  For checkboxes only the checked 
elements come through so you need values that determine which box was checked. So say 
you have:
input type=checkbox name=box[] value=box_1  
input type=checkbox name=box[] value=box_2  checked
input type=checkbox name=box[] value=box_3  checked

$box[0] == box_2
$box[1] == box_3

-- 
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]