One of my senior ask me that, what is the difference between $ and $$ (in php)?
Can u guys help me ?
3 replies to this topic
#1
Posted 17 November 2011 - 09:42 PM
|
|
|
#2
Posted 17 November 2011 - 10:54 PM
Agree, googling for "$" doesn't give you much, so here are the actual names:
$ = php variable
$$ = php variable variable(Ye seriously)
google it.
$ = php variable
$$ = php variable variable(Ye seriously)
google it.
#3
Posted 17 November 2011 - 11:41 PM
I got the answer with little confusion....
Actually here we use a value(Christine_Nothdurfter) of variable as a variable name($Christine_Nothdurfter).... But what is the use of it ?
Actual code:
<?php
error_reporting(E_ALL);
$name = "Christine_Nothdurfter";
// not Christine Nothdurfter
// you are not allowed to leave a space inside a variable name ;)
$$name = "'s students of Tyrolean language ";
print " $name{$$name}<br>";
print "$name$Christine_Nothdurfter";
// same
?>
Output :
Christine_Nothdurfter's students of Tyrolean language
Christine_Nothdurfter's students of Tyrolean language
Actually here we use a value(Christine_Nothdurfter) of variable as a variable name($Christine_Nothdurfter).... But what is the use of it ?
Actual code:
<?php
error_reporting(E_ALL);
$name = "Christine_Nothdurfter";
// not Christine Nothdurfter
// you are not allowed to leave a space inside a variable name ;)
$$name = "'s students of Tyrolean language ";
print " $name{$$name}<br>";
print "$name$Christine_Nothdurfter";
// same
?>
Output :
Christine_Nothdurfter's students of Tyrolean language
Christine_Nothdurfter's students of Tyrolean language
#4
Posted 20 November 2011 - 01:11 AM
You can have variable variables. For example, if you in object oriented programming don't know what class you need to instanciate, you can do
Now $object is a object of type myclass, which could be changed to whatever from for example a database query teling which class to use.
$class = "myclass"; $object = new $class();
Now $object is a object of type myclass, which could be changed to whatever from for example a database query teling which class to use.
__________________________________________
I study Information Systems at Karlstad University when I'm not on CodeCall
I study Information Systems at Karlstad University when I'm not on CodeCall
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









