NaN:NaN
NaN:NaN
--:-- / --:--
Newgrounds Background Image Theme

DareDiavolo just joined the crew!

We need you on the team, too.

Support Newgrounds and get tons of perks for just $2.99!

Create a Free Account and then..

Become a Supporter!

Double Dollarsigns

778 Views | 7 Replies
New Topic Respond to this Topic

Double Dollarsigns Nov 20, 2006


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

Response to Double Dollarsigns Nov 20, 2006


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 ]

BBS Signature

Response to Double Dollarsigns Nov 20, 2006


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?

Response to Double Dollarsigns Nov 20, 2006


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.

Response to Double Dollarsigns Nov 20, 2006


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.


Merkd.com - It Pays to Play

Earn real money by betting and investing; or, sponsor, challenge, compete,

recruit, communicate, network, earn money playing games, and much more.

Response to Double Dollarsigns Nov 21, 2006


That's one thing i didn't know in php. Thanks.


BBS Signature

Response to Double Dollarsigns Nov 21, 2006


It would also work as $bleep$blap , right?

Response to Double Dollarsigns Nov 21, 2006


Yeah, Nice hint Doofy!