When to use a variable variable in PHP?

The place for general PHP questions and hints for PHP on IBM i
Post Reply
indr9864
Posts: 1
Joined: Wed May 31, 2017 9:01 am
Contact:

When to use a variable variable in PHP?

Post by indr9864 » Wed May 31, 2017 9:03 am

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 ?

anab6077
Posts: 1
Joined: Mon Jun 26, 2017 9:07 am
Contact:

Re: When to use a variable variable in PHP?

Post by anab6077 » Mon Jun 26, 2017 9:10 am

I also have the same problem. Looking help from someone.

mani3164
Posts: 1
Joined: Thu Jun 29, 2017 10:23 am
Contact:

Re: When to use a variable variable in PHP?

Post by mani3164 » Thu Jun 29, 2017 10:50 am

Variable use Doller sign

frie3144
Posts: 2
Joined: Sat Jul 08, 2017 6:41 am
Contact:

Re: When to use a variable variable in PHP?

Post by frie3144 » Sat Jul 08, 2017 6:44 am

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.

frie3144
Posts: 2
Joined: Sat Jul 08, 2017 6:41 am
Contact:

Re: When to use a variable variable in PHP?

Post by frie3144 » Sat Jul 08, 2017 7:01 am

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.

alek76
Posts: 8
Joined: Tue Aug 29, 2017 9:57 pm

Re: When to use a variable variable in PHP?

Post by alek76 » Tue Aug 29, 2017 10:24 pm

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.

neha550
Posts: 12
Joined: Tue Jan 09, 2018 6:29 am
Location: Chennai
Contact:

Re: When to use a variable variable in PHP?

Post by neha550 » Tue Jan 09, 2018 7:53 am

I use it for loading existing user values from the database. I use it for passing my form fields back to smarty:

Bepannaah
Posts: 1
Joined: Tue May 15, 2018 1:47 am

Re: When to use a variable variable in PHP?

Post by Bepannaah » Tue May 15, 2018 1:51 am

Thank you so much for sharing such a superb informations with us. Your website is very cool. we are impressed by the details that you have on your site.we Bookmarked this website. Thanks again
http://bepannaah.com/

Post Reply