Page 1 of 1

When to use a variable variable in PHP?

PostPosted: Wed May 31, 2017 9:03 am
by indr9864
I've been developing in PHP for a while now, and I still have not had a task where I've had to use variable variables. Can anyone give me examples where using them is a good idea ? Or were they included in the language for no reason ?

Re: When to use a variable variable in PHP?

PostPosted: Mon Jun 26, 2017 9:10 am
by anab6077
I also have the same problem. Looking help from someone.

Re: When to use a variable variable in PHP?

PostPosted: Thu Jun 29, 2017 10:50 am
by mani3164
Variable use Doller sign

Re: When to use a variable variable in PHP?

PostPosted: Sat Jul 08, 2017 6:44 am
by frie3144
Friendship day is celebrated on the first Sunday of August in every year. This day is also special for your friendship if you have the best friend or if you have any loyal, faithful friend.

Re: When to use a variable variable in PHP?

PostPosted: Sat Jul 08, 2017 7:01 am
by frie3144
Friendship day is celebrated on the first Sunday of August in every year. This day is also special for your friendship if you have the best friend or if you have any loyal, faithful friend.

Re: When to use a variable variable in PHP?

PostPosted: Tue Aug 29, 2017 10:24 pm
by alek76
I use those very rarely. Usually when you have some sort of condition:

Code: Select all
if ($a){
$varname = 'fullname';
} else {
$varname = 'name';
}
echo $$varname;


This is the same as

Code: Select all
if ($a){
echo $fullname;
} else {
echo $name;
}


And although this is a simple case in which there is no need to use the variable variable - you may get more complex cases where that is the only way to achieve the desired result.