Execute command from array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
I have an array, say something like this (to build a form):

$commands = array(
"Start Date" => "build_date('startdate')",
"End Date" => "build_date('enddate')"

Only it will have many more entries. I want to cycle through the array,  
and print the first part, but then execute the second part so that it  
goes to the function build_date (which returns html code to output).

Right now I am doing it something like this:

echo "<tr><td>Start date</td><td>";
echo build_date('startdate');
echo "</td><td>End date</td><td>";
echo build_date('enddate');
echo "</td></tr>";

Because this is going to have many entries in it, it is getting very  
repetitive to do it this way! I am stuck on how to execute that function  
(and pass the string) with it already being a string itself.

Any ideas?

Re: Execute command from array

*** Dave Thomas wrote/escribió (Thu, 11 Aug 2005 15:44:33 -0400):
Quoted text here. Click to load it

Check foreach() and eval().

-- Álvaro G. Vicario - Burgos, Spain
-- http://bits.demogracia.com - Mi sitio sobre programación web
-- Don't e-mail me your questions, post them to the group

Re: Execute command from array

foreach ($commands as $key=>$val) {
   echo "<tr><td>$key</td></tr>";
   echo eval("$val;");
echo "</td></tr>";

Site Timeline