Answer the question
In order to leave comments, you need to log in
Using $$ in PHP?
In the source code of Bitrix, I came across such a thing
if ($REQUEST_METHOD=="POST" && strlen($Update)>0)
{
foreach($arAllOptions as $option)
{
$name = $option[0];
$val = $$name;
COption::SetOptionString("main", $name, $val);
}
}
$_REQUEST["foo"] = "bar"
. echo $foo \\ выведет bar
Answer the question
In order to leave comments, you need to log in
And what does Bitrix have to do with it, this is a classic way of using named variables
$array = ['title'=>'TITLE','slug'=>'URL','contet'=>'CONTENT.....'];
foreach ($array as $key => $value) {
$$key = $value;
}
echo $title; // TITLE
echo $slug; // URL
echo $contet; // CONTENT.....
You have found the absolutely correct "joke" of Bitrix, it's "ugly" :) it creates such variables with this line:$val = $$name;
These are variable variables, here is an example
<?
$first = "second";
$second = "third";
echo $first; //second
echo "\n";
echo $$first; //third
?>
A classic example of such things
class Foo {
public $deepest = 10;
public function __toString()
{
return 'deep';
}
}
$deeper = 'deepest';
$deep = 'deeper';
$b = new Foo();
echo $b->$$$b;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question