note 84823 deleted from language.variables.variable by danbrown
| From: | danbrown@php.net | Date: | Thu, 31 Jul 2008 19:56:08 +0000 |
| Subject: | note 84823 deleted from language.variables.variable by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-142986@lists.php.net to get a copy of this message | ||
Note Submitter: david at midsever dot com
Reason: in docs
----
You can use a variable variable to hold the name of a function like this:
$m = 'somefunction'; // note no parenthesis
and use the variable as the function like this:
$m()
You can use a variable variable to hold the name of a list of functions to loop through like this:
$m[0] = 'function1';
$m[1] = 'function2';
$m[2] = 'function3';
and loop through the array to execute each function like this:
for($i=0; $i<$counter; $i++)
{
echo $m[$i]();
}
I actually created modules where each module was a function that displayed specific content on the
page. Each function displayed something different. Then users were given the capability to select
from those modules to choose what would be displayed on the page and where at on the page. This
allowed me to loop through the list of functions I created to select those that had been chosen by
each user and giving the page a completely unique look. So far I haven't found any problems.