Page 1 of 1

Inserting variable $_GET array element's name

Posted: Mon Dec 16, 2002 11:08 am
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

Posted: Mon Dec 16, 2002 3:37 pm
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.

Posted: Tue Dec 17, 2002 3:19 am
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

Posted: Tue Dec 17, 2002 11:03 am
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']}'"; 
?>

Posted: Tue Dec 17, 2002 11:18 am
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.

Posted: Wed Dec 18, 2002 5:17 am
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

Posted: Wed Dec 18, 2002 12:41 pm
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