Page 1 of 1

switch statement

Posted: Thu Nov 21, 2002 3:57 am
by ridwan
I am wondering is it possible to allow a statement like the following to work out :

Code: Select all

<?php
switch ($infoa)
{
case "1a"
break;
case "2a"
break;
case "3a"
break;
if a='a'  {
}
switch ($infob)
{
case "1b"
break;
case "2b"
break;
case "3b"
break;
} 
} else 
{
plain info
}
}
?>
I have checked my manual but am not to sure 'cos it doesn't say anything about this particular scenario :? ???

I am not too worried about the syntax but more about the structure and workings of it all....

thanks



?>

Posted: Thu Nov 21, 2002 4:20 am
by twigletmac
I'm not sure exactly what you are trying to achieve - are you trying to nest if's and switches within another switch?

Mac

Posted: Thu Nov 21, 2002 4:44 am
by ridwan
yes, b'cos I am currently getting error's with my code and was wondering whether it is possible to be done in the first place; before triple checking my code to see whether it's me or php

Posted: Thu Nov 21, 2002 5:02 am
by twigletmac
It's possible, assuming that you want the if statement and second switch to run on the default statement of the first switch, try something like:

Code: Select all

<?php 
$infoa = '';
$infob = '';
$a = 'a';

switch ($infoa) { 
	case '1a': 
		break; 
	case '2a': 
		break; 
	case '3a': 
		break;
	default:
		echo '<p>default for first switch</p>';
		if ($a = 'a') { 
			switch ($infob) { 
				case '1b': 
					break; 
				case '2b': 
					break; 
				case '3b': 
					break;
				default:
					echo '<p>default for second switch</p>';
			}
		} else { 
			//plain info 
		} 
} 
?>
Mac

Posted: Thu Nov 21, 2002 5:38 am
by ridwan
gr8 b'cos that's exactly where it's happening

thanx again twigletmac