Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Jan 2011
    Posts
    90
    Thanks
    4
    Thanked 5 Times in 5 Posts

    what does $$ in php means?

    I know $ is for variables but what does $$ means?

  • #2
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    "variable variables"

    It's hard to describe because it sort of bends your mind ...
    at times, I get so lost in it, like a paradox.

    Take a look here and let me know if it messes with your mind ...
    http://php.net/manual/en/language.va...s.variable.php


    .
    Last edited by mlseim; 11-24-2011 at 05:22 AM.

  • #3
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    PHP Code:
    $a "value of var a";

    $b "a";

    echo $
    $b
    simple example. hehe.
    I am sorry my english is very bad. But I am very interest to discusse here :-)

  • #4
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Quote Originally Posted by XterM View Post
    PHP Code:
    $a "value of var a";

    $b "a";

    echo $
    $b
    simple example. hehe.
    This is about the easiest way to think of it. Variable variables are simply dereferencing two levels of variables. So dereferencing $b becomes 'a', and then it seeks to dereference 'a' with a returned result of 'value of var a'.
    The only thing I have to add is that there is yet to be a situation in which I've found variable variables useful. Standard copy assignment or referenced variables do exactly the same, except referenced assignments cannot swap what they point at ($b can be changed to point at $c, and $$b would then dereference $c instead of $a, but there is little use to variable variables at all).
    Variable variables would actually be quite popular if PHP didn't use copy-on-write optimization. Since it does, variable variables are pretty much obsolete.

  • Users who have thanked Fou-Lu for this post:

    XterM (11-25-2011)

  • #5
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    oops ... double posted.
    Last edited by mlseim; 11-24-2011 at 09:21 PM.

  • #6
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    This is about the easiest way to think of it. Variable variables are simply dereferencing two levels of variables. So dereferencing $b becomes 'a', and then it seeks to dereference 'a' with a returned result of 'value of var a'.
    like I can understand that.

    I've only used them one time, with Perl.
    I don't remember why I needed to use them.

  • #7
    New Coder
    Join Date
    Jul 2011
    Location
    Kediri - Indonesia
    Posts
    61
    Thanks
    2
    Thanked 19 Times in 19 Posts
    Quote Originally Posted by Fou-Lu View Post
    This is about the easiest way to think of it. Variable variables are simply dereferencing two levels of variables. So dereferencing $b becomes 'a', and then it seeks to dereference 'a' with a returned result of 'value of var a'.
    The only thing I have to add is that there is yet to be a situation in which I've found variable variables useful. Standard copy assignment or referenced variables do exactly the same, except referenced assignments cannot swap what they point at ($b can be changed to point at $c, and $$b would then dereference $c instead of $a, but there is little use to variable variables at all).
    Variable variables would actually be quite popular if PHP didn't use copy-on-write optimization. Since it does, variable variables are pretty much obsolete.
    wow. that is very understandable. thanks bro
    I am sorry my english is very bad. But I am very interest to discusse here :-)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •