variables - PHP what does it mean when using this '$$var'? -


this question has answer here:

i trying learn php, , saw in foreach loop mean? understand &$var direct reference memory address of object. $$var means? exactly?

this example.

    foreach($this->vars $key => $value)     {         $$key = $value;         echo "$$key: " . $$key;         echo "key: " . $key;         echo "<br/>";         echo "value: " . $value;     } 

you're looking @ variable variable. e.g.

// original variable named 'foo' $foo = "bar";  // reference $foo dynamically evaluating $x $x = "foo"; echo $$x; // "bar"; echo ${$x}; // "bar" {} allows perform concatenation  // different version of {} show more "complex" operation $y = "fo"; $z = "o"; echo ${$y . $z}; // "bar" ("fo" . "o" = "foo") 

to show example more closely matching question:

$foo = "foo"; $bar = "bar"; $baz = "baz";  $ary = array('foo' => 'foo','bar' => 'bar','baz' => 'baz'); foreach ($ary $key => $value){   $$key = $value; }  // end result is: // $foo = "foo"; // $bar = "bar"; // $baz = "baz"; 

Comments

Popular posts from this blog

iphone - Three second countdown in cocos2d -

hyperlink - how to do url routing in php -

c - Avoiding Extra Malloc in Linked List (node->next = NULL) -