Rabu, 04 Mei 2011

Indirect References to Variables

An extremely useful feature of PHP is that you can access variables by using indirect references, or to put it simply, you can create and access variables by name at runtime.
Consider the following example:
$name = "John";
$$name = "Registered user";
print $John;<span class="fullpost">

This code results in the printing of "Registered user."
The bold line uses an additional $ to access the variable with name specified by the value of $name ("John") and changing its value to "Registered user". Therefore, a variable called $John is created.
You can use as many levels of indirections as you want by adding additional $ signs in front of a variable.</span>

Tidak ada komentar:

Posting Komentar