Inserting variable $_GET array element's name

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kamal
Forum Newbie
Posts: 8
Joined: Fri Sep 13, 2002 5:35 am
Location: Rome, Italy

Inserting variable $_GET array element's name

Post by kamal »

Hello everybody.
How can I write something like this:

Code: Select all

$param = "$param_name => '" . $_GETї"p_$i"] . "'";
without "concat"?
Having something like this:

Code: Select all

$param = "$param_name => '$_GETї"p_$i"]'";
Thank you

Kamal
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

Are you trying to create a new array?

How about doing this:

Code: Select all

$param = array($param_name => $_GETї"p_$i"]);
Or simply :

Code: Select all

$paramї$param_name] = $_GETї"p_$i"];
If it's not the case I don't understand your question I hope someone else does though.
kamal
Forum Newbie
Posts: 8
Joined: Fri Sep 13, 2002 5:35 am
Location: Rome, Italy

Post by kamal »

Oh, sorry... forget the "=>" symbol... that's just a string I wanted inside the variable, tou can write it also this way:

Code: Select all

$var = "something ' $_GETї"p_$i"] ' something else";
In this case, i want the $_GET array to be parametric. (Does this word exist in english? I don't know.)

For example, in a loop, i want first $_GET["p_0"], then $_GET["p_1"], etc etc. And i want to put the value of $_GET["p_0"], $_GET["p_1"] inside two ' (single quotes), having them (the quotes) considered literally.

Thank you

Kamal
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Code: Select all

<?php
$param = "$param_name => '" . $_GET["p_$i"] . "'"; 
?>
That's the orginal and change it to this:-

Code: Select all

<?php
$param = "$param_name => '{ $_GET['p_$i']}'"; 
?>
User avatar
puckeye
Forum Contributor
Posts: 105
Joined: Fri Dec 06, 2002 7:26 pm
Location: Joliette, QC, CA
Contact:

Post by puckeye »

kamal wrote:Oh, sorry... forget the "=>" symbol... that's just a string I wanted inside the variable, tou can write it also this way:

Code: Select all

$var = "something ' $_GET&#1111;"p_$i"] ' something else";
In this case, i want the $_GET array to be parametric. (Does this word exist in english? I don't know.)

For example, in a loop, i want first $_GET["p_0"], then $_GET["p_1"], etc etc. And i want to put the value of $_GET["p_0"], $_GET["p_1"] inside two ' (single quotes), having them (the quotes) considered literally.

Thank you

Kamal
In this case do it this way:

Code: Select all

$var = "something ' $_GET&#1111;"p_$i"] ' something else";
Escaping the 2 quotes around your p_$i variable will probably do the trick.
kamal
Forum Newbie
Posts: 8
Joined: Fri Sep 13, 2002 5:35 am
Location: Rome, Italy

Post by kamal »

Thank you both puckeye and Takuma but this two solutions didn't work:

Code: Select all

$var = "something ' $_GET&#1111;"p_$i"] ' something else";

$var = "something '&#123; $_GET&#1111;'p_$i']&#125;' something else";
But this worked:

Code: Select all

$var = "something '&#123; $_GET&#1111;"p_$i"]&#125;' something else";
Just putting double quotes instead of single quotes in Takuma's solution.

Thank you

Kamal
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Mmm interesting, I was confused what will happen when I was writing it for you. Whether it would create an area or something... Well it worked so :D
Post Reply