variables question

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
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

variables question

Post 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];
pedroz
Forum Commoner
Posts: 99
Joined: Thu Nov 03, 2005 6:21 am

Post by pedroz »

In other words what I need is

$a='world';

$hello$a='ok';

echo $helloworld;
// ok
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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]; 
}
User avatar
umang
Forum Newbie
Posts: 1
Joined: Mon Mar 13, 2006 1:11 am
Location: MUmbai
Contact:

Re: variables question

Post 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;

}
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Re: variables question

Post 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.
Post Reply