note 84823 added to language.variables.variable
| From: | david at midsever dot com | Date: | Thu, 31 Jul 2008 19:52:50 +0000 |
| Subject: | note 84823 added to language.variables.variable | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-142985@lists.php.net to get a copy of this message | ||
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.
----
Server IP: 208.69.120.35
Probable Submitter: 66.109.244.18
----
Manual Page -- http://www.php.net/manual/en/language.variables.variable.php
Edit -- https://master.php.net/note/edit/84823
Del: integrated -- https://master.php.net/note/delete/84823/integrated
Del: useless -- https://master.php.net/note/delete/84823/useless
Del: bad code -- https://master.php.net/note/delete/84823/bad+code
Del: spam -- https://master.php.net/note/delete/84823/spam
Del: non-english -- https://master.php.net/note/delete/84823/non-english
Del: in docs -- https://master.php.net/note/delete/84823/in+docs
Del: other reasons-- https://master.php.net/note/delete/84823
Reject -- https://master.php.net/note/reject/84823
Search -- https://master.php.net/manage/user-notes.php