Example is a variable declaration within a function:
global $$link;
What does $$
mean?
A syntax such as $$variable
is called Variable Variable.
For example, if you consider this portion of code :
$real_variable = 'test';
$name = 'real_variable';
echo $$name;
You will get the following output :
test
Here :
$real_variable
contains test$name
contains the name of your variable : 'real_variable'
$$name
mean "the variable thas has its name contained in $name
"
$real_variable
'test'
EDIT after @Jhonny's comment :
Doing a $$$
?
Well, the best way to know is to try ;-)
So, let's try this portion of code :
$real_variable = 'test';
$name = 'real_variable';
$name_of_name = 'name';
echo $name_of_name . '<br />';
echo $$name_of_name . '<br />';
echo $$$name_of_name . '<br />';
And here's the output I get :
name
real_variable
test
So, I would say that, yes, you can do $$$
;-)
It's a variable's variable.
<?php
$a = 'hello';
$$a = 'world'; // now makes $hello a variable that holds 'world'
echo "$a ${$a}"; // "hello world"
echo "$a $hello"; // "hello world"
?>
It creates a dynamic variable name. E.g.
$link = 'foo';
$$link = 'bar'; // -> $foo = 'bar'
echo $foo;
// prints 'bar'
(also known as variable variable)
this worked for me (enclose in square brackets):
$aInputsAlias = [
'convocatoria' => 'even_id',
'plan' => 'acev_id',
'gasto_elegible' => 'nivel1',
'rubro' => 'nivel2',
'grupo' => 'nivel3',
];
/* Manejo de los filtros */
foreach(array_keys($aInputsAlias) as $field)
{
$key = $aInputsAlias[$field];
${$aInputsAlias[$field]} = $this->request->query($field) ? $this->request->query($field) : NULL;
}
${$link}
in Bash – Ondra Žižka