Re: problems with switch()
| From: | Mark A Mucha | Date: | Sat, 08 Jul 2000 01:15:36 +0000 |
| Subject: | Re: problems with switch() | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-5498@lists.php.net to get a copy of this message | ||
The problem is this, you don't have semicolons after you declare x = 1, nor
after the break statements
Add the ; behind each of them and it works.
<html>
<body>
<? $x = 1;
switch ($x) {
case 1: ?>
x = 1
<? break;
default:
echo "";
?>
x != 1
<? break;
} ?>
</body>
</html>
----- Original Message -----
From: "August Zajonc" <augustz@bigfoot.com>
To: "J.R. Lillard" <jr@hyphen.org>; <php-general@lists.php.net>
Sent: Friday, July 07, 2000 8:47 PM
Subject: RE: [PHP] problems with switch()
> default: may not like having no statement folloring it. What about
> adding echo ""; on the next line?
>
> August
>
>
> > -----Original Message-----
> > From: J.R. Lillard [mailto:jr@hyphen.org]
> > Sent: Friday, July 07, 2000 8:22 PM
> > To: php-general@lists.php.net
> > Subject: [PHP] problems with switch()
> >
> >
> > i'm running php 4.0. most of my code looks something like this:
> >
> > <html>
> > <body>
> > <? $x = 1 ?>
> > <? if ($x == 1) { ?>
> > x = 1
> > <? } else { ?>
> > x != 1
> > <? } ?>
> > </body>
> > </html>
> >
> > i know that may not be the easiest thing for the parser to
> > parse, but it's
> > easier for me to read it. basically i'm going in and out of php code
> > through the block of the if() statement. but if i do
> > something like this:
> >
> > <html>
> > <body>
> > <? $x = 1 ?>
> > <? switch ($x) { ?>
> > <? case 1: ?>
> > x = 1
> > <? break ?>
> > <? default: ?>
> > x != 1
> > <? } ?>
> > </body>
> > </html>
> >
> > i get this error:
> >
> > Parse error: parse error, expecting
T_CASE' or
> > T_DEFAULT' or `'}''
> >
> > referencing the line right after the switch() statement. but if i do
> > this:
> >
> > <html>
> > <body>
> > <? $x = 1 ?>
> > <?
> > switch ($x) {
> > case 1:
> > echo "x = 1";
> > break;
> > default:
> > echo "x != 1";
> > }
> > ?>
> > </body>
> > </html>
> >
> > it works just fine. is there any reason i can't jump in and
> > out of php
> > code in the block of a switch() statement? it works just
> > fine with if()s,
> > while()s, and for()s.
> >
> > -jr
> >
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> > For additional commands, e-mail: php-general-help@lists.php.net
> > To contact the list administrators, e-mail:
> > php-list-admin@lists.php.net
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>