variables - PHP what does it mean when using this '$$var'? -
this question has answer here:
- reference — symbol mean in php? 15 answers
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
Post a Comment