2 ms·
It's actually slightly wrong to just say "variables start with $". It's more like "$ dereferences a string": $foo = "I am foo\n"; $bar = "foo"; echo $$b
by Izkata 6y ago
It's actually slightly wrong to just say "variables start with $". It's more like "$ dereferences a string":
$foo = "I am foo\n";
$bar = "foo";
echo $$bar;
This is in the documentation under "variable variables" [0]. This also lets you create dynamic function names:
function run_foo() {
echo "I'm a foo\n";
}
$method = 'foo';
$picked = "run_$method";
$picked();
[0] https://www.php.net/manual/en/language.variables.variable.php https://www.php.net/manual/en/language.variables.variable.ph...