Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

What is the difference between $name and $$name in PHP?

abhikabhik bangalore, IndiaMember Posts: 1

Hi,
What is the difference between $name and $$name in PHP?

Tagged:

Comments

  • B00B00 Member Posts: 77 ✭✭✭

    Double dollar sign makes a variable with the name equal to value of original variable.

    $var = 'foo';
    $$var = 'bar';
    echo $foo; // output: bar
    
  • SwatiSwati DelhiMember Posts: 1
    edited July 2016

    $name is variable where as
    $$name is reference variable like $name=swati
    and $$name=tyagi so $swati value is tyagi

    Example with output
    $a="Swati Tyagi";
    $xyz="a";
    echo $$xyz

    Output would be :
    //Swati Tyagi

    For more precise answer Difference between $name and $$name in PHP

  • Snehal AgravalSnehal Agraval IndiaMember Posts: 2
    $$name is a variable generates runtime 
    
    let's 
    
    $name='osama';
    
    $$name ='feras';
    

    now we have two variable the first one $name and the second one $osama

    echo $osama ;
    
    the output  is :  feras
    

    $this is a special variable that can't be assigned .but you can declare $this variable using "$$"

    let's

    $name='this';
    
    $$name ='feras';
    
    echo $this;
    
    the output  will be :  feras
    

    Learn PHP https://hackr.io/tutorials/learn-php

Sign In or Register to comment.