switch statement

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

switch statement

Post 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



?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

Post 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
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

Post by ridwan »

gr8 b'cos that's exactly where it's happening

thanx again twigletmac
Post Reply