Can someone please explain me double dollarsigns in PHP ?
Please?
I tried to Google it but I got a BBS post on NG which I recently made.
lol
Can someone please explain me double dollarsigns in PHP ?
Please?
I tried to Google it but I got a BBS post on NG which I recently made.
lol
Well, to say it with an example...
$var = "hello";
$$var = "Yay!";
echo $hello;
It *should* output 'Yay!'.
Also, http://be2.php.net/manual/en/language.variabl es.variable.php
"My software never has bugs. It just develops random features. " - Unknown
[ FluxBB developer | Quickmarks 0.5.1 | Strings & Ints - my blog ]
Double dollar signs are pretty simple. It's calling a variable with a variable name.
So, the following script:
<?php
$name = 'david';
$$namevar = 'this is a test.';
echo $davidvar;
?>
So what happens is the contents of $name is applied to the variable name making a variable called $davidvar.
Understand now?
At 11/20/06 02:34 PM, DFox wrote: Double dollar signs are pretty simple. It's calling a variable with a variable name.
So, the following script:
<?php
$name = 'david';
$$namevar = 'this is a test.';
echo $davidvar;
?>
So what happens is the contents of $name is applied to the variable name making a variable called $davidvar.
Understand now?
Quite a bit, thanks!
And thanks Elbekko for that link, it was very helpful.
Just a little note, I find this very useful when I'm storing form information in variables rather than arrays. Let's say we want to apply htmlentities() to all POST values and store them with variable names. You could do this:
foreach($_POST as $foo=>$bar) {
$$foo = htmlentities($bar);
}
It can be very useful so you don't have to type long forms each time you reference something. And you don't have to manually define each one.
Earn real money by betting and investing; or, sponsor, challenge, compete,
recruit, communicate, network, earn money playing games, and much more.