|
Posted by Juliette on 10/22/06 18:10
wouter wrote:
> hey hi.....
>
> I wanna make a switch wich does this:
>
> if pagid is set do A,
> if catid is set do B,
> if projectid is set do C,
> else do D.
>
> So i was thinking something like this:
>
> switch()
> {
> case isset ($_GET['pagid']):
> {
> echo "pagid= set";
> }
> break;
> case isset ($_GET['catid']):
> {
> echo "catid= set";
> }
> break;
> case isset ($_GET['projectid']):
> {
> echo "projectid= set";
> }
> break;
> default:
> {
> echo "nothing set";
> }
> }
>
>
> wich works great in my mind but not on my server....
>
> Anybody here know how to do this in a way wich does work??
switch( true )
{
Contrary to the (non-)problem highlighted by another poster, having
several expressions here that could be true, is not a problem.
Switch will execute the first case it comes across which is valid. If
that case is closed by 'break;', it will then terminate the switch, if
the case is closed by 'continue;' it will continue to evaluate the other
options too.
In other words choosing the order of your cases is very important if you
use this syntax when several cases can be true.
On another note: the curly braces within your cases are not needed, a
brace surrounding your isset's is recommended. I.e.:
> case isset ($_GET['pagid']):
> {
> echo "pagid= set";
> }
> break;
Would become:
case ( isset ($_GET['pagid']) ):
echo "pagid= set";
break;
or further on the case statement:
case ( isset ($_GET['pagid']) === true ):
Grz, Juliette
Navigation:
[Reply to this message]
|