problems with switch()
| From: | J.R. Lillard | Date: | Sat, 08 Jul 2000 00:22:03 +0000 |
| Subject: | problems with switch() | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-5494@lists.php.net to get a copy of this message | ||
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