RE: [PHP] problems with switch()

From: Date: Sat, 08 Jul 2000 00:47:05 +0000
Subject: RE: [PHP] problems with switch()
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-5495@lists.php.net to get a copy of this message
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

« previous php.general (#5495) next »