Jump to content

What is the usage of $$ in php ?

- - - - -

  • Please log in to reply
3 replies to this topic

#1
murugavelb

murugavelb

    Newbie

  • Members
  • PipPip
  • 11 posts
One of my senior ask me that, what is the difference between $ and $$ (in php)?
Can u guys help me ?

#2
wim DC

wim DC

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 2,084 posts
  • Programming Language:Java, JavaScript, PL/SQL
  • Learning:Java
Agree, googling for "$" doesn't give you much, so here are the actual names:

$ = php variable
$$ = php variable variable(Ye seriously)

google it.

#3
murugavelb

murugavelb

    Newbie

  • Members
  • PipPip
  • 11 posts
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

#4
Orjan

Orjan

    Writes binary right handed and hex left handed

  • Moderators
  • 3,299 posts
  • Location:Karlstad, Sweden
  • Programming Language:C, Java, C++, C#, PHP, JavaScript, Pascal
  • Learning:Java, C#
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

$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




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users