Page 1 of 1

switch statement...

Posted: Mon Jan 31, 2005 6:19 am
by dmakris
Hello.
I am sending the switch statement i use.
Cases 1,2,3 are the results of a selection box that I use in my form.
What I need is NOT to print the values on screen (using the echo command) but save each value to a variable so I can use the value later.

Anybody can help?
Thanks in advance


switch ($tmethod) {
case "1":
echo= "value 1";
break;

case "2":
echo= " value 2";
break;

case "3":
echo= " value 3";
break;
}

Posted: Mon Jan 31, 2005 6:25 am
by timvw
ah values that come from a form, those you can find in $_POST and $_GET nowadays. You probably want to read the whole section, starting from http://www.php.net/variables

Code: Select all

if (isset($_POSTї'tmethod']))
{
    switch($_POSTї'tmethod'])
    {
         case '1':
            $value = "foo";
            break;
          case '2':   // fallthrough
           case '3':
              $value = "bar";
              break;
           default:
               $value = "default";
     }
}