Check out php golfing tips CGSE
Variable variables
These special variables are denoted usually with a extra $ symbol: ${$x}
, or $$x
. Variables names are evaluated as strings. Pure numbers can also be used as variable names:
$a=1;$$a=5;$a++;$$a=4;${++$a}=3;echo${1},${2},${3}
>> 543
The usual way to use this in golfing is to get rid of a declaration:
for(;$t++<9;)for($a=0;$a++<$t;)...
for(;$t++<9;)for(;$$t++<$t;)...
Here $$t
is set to 0 every time $t++
is executed.
This can also be used to save on accessing arrays: eg: $$n
instead of $a[$n]
.