Page 1 of 1

variables question

Posted: Wed Mar 22, 2006 3:18 am
by pedroz

Code: Select all

$_GET['action']=$includeaction;
$_GET['forum']=$includeforum; 
$_GET['topic']=$includetopic; 
........ more

I have several $_GET's that I would like to put in array.
What is wrong with the code above?
Seems to be this...
$include$includevar[$i]

Code: Select all

$includevar=array('action','forum','topic',....... more);
for ($i=0; $i<count($includevar); $i++) $_GET[''.$includevar[$i].'']=$include$includevar[$i];

Posted: Wed Mar 22, 2006 3:48 am
by pedroz
In other words what I need is

$a='world';

$hello$a='ok';

echo $helloworld;
// ok

Posted: Wed Mar 22, 2006 4:02 am
by patrikG
not quite clear what you're trying to achieve. It appears as if you want to concatenate strings.
If that is so, use . between string variables to do that.

Code: Select all

for ($i=0; $i<count($includevar); $i++) {
    $_GET[$includevar[$i]]=$include.$includevar[$i]; 
}

Re: variables question

Posted: Wed Mar 22, 2006 5:04 am
by umang
hi,


you need only

Code: Select all

extract($_GET);
function to call and you get array of that

and wan a use them

use like:

Code: Select all

foreach ( $_GET as $key => $val)
{
    echo $key;
    echo "<br>";
     echo $val;

}

Re: variables question

Posted: Wed Mar 22, 2006 5:06 am
by patrikG
umang wrote:hi,


you need only

Code: Select all

extract($_GET);
function to call and you get array of that

and wan a use them

use like:

Code: Select all

foreach ( $_GET as $key => $val)
{
    echo $key;
    echo "<br>";
     echo $val;

}
That's a security risk and opens the door for sql- and code-injection.