php-general | 2003022
Date: 02/21/03
- Next message: Matt Honeycutt: "RE: [PHP] Re: including in shtml"
- Previous message: olinux: "Re: [PHP] user registration system"
- Next in thread: David T-G: "Re: [PHP] Array instead of Switch"
- Reply: David T-G: "Re: [PHP] Array instead of Switch"
- Reply: David Otton: "Re: [PHP] Array instead of Switch"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Let's say I need to take one of 20 actions depending on a form selection. I
could use a switch statement with 20 cases, but I could also do something
like:
// Pretend this comes from a form
$formchoice = "mars";
$response = array(
"mars" => "go_mars()",
"mercury" => "go_mercury()",
"earth" => "go_earth()");
foreach ($response as $choice => $action)
{
if (strtoupper($formchoice) == strtoupper($choice))
{
eval("$action;");
}
}
But are there even better ways?
-- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
- Next message: Matt Honeycutt: "RE: [PHP] Re: including in shtml"
- Previous message: olinux: "Re: [PHP] user registration system"
- Next in thread: David T-G: "Re: [PHP] Array instead of Switch"
- Reply: David T-G: "Re: [PHP] Array instead of Switch"
- Reply: David Otton: "Re: [PHP] Array instead of Switch"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]

