note 9867 modified in control-structures.switch by joey

From: Date: Fri, 07 Jun 2002 23:19:53 +0000
Subject: note 9867 modified in control-structures.switch by joey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-31588@lists.php.net to get a copy of this message
You can also use this form of switch: <?switch ( $test ) case 'foo' :?> <FONT face="verdana">Foo</FONT> <?case 'bar' :?> <FONT face="verdana">Bar</FONT> <?default :?> <FONT face="verdana">Default</FONT> <?endswitch ;?> If $text is foo, you get all three results. If $text is bar, you get the last two. If it's neither, you get only the last one. Adding breaks would look like this: <?switch ( $test ) :?> <?case 'foo' :?> <FONT face="verdana">Foo</FONT> <?break ;?> <?case 'bar' :?> <FONT face="verdana">Bar</FONT> <?default :?> <?break ;?> <FONT face="verdana">Default</FONT> <?endswitch ;?> or this: <?switch ( $test ) :?> <?case 'foo' :?> <FONT face="verdana">Foo</FONT> <?break ; case 'bar' :?> <FONT face="verdana">Bar</FONT> <?break ; default :?> <FONT face="verdana">Default</FONT> <?endswitch ;?> It may look strange, but it really helps when you have blocks of HTML avoiding lines like: <?}?> --was-- You can also use this form of switch: <?switch ( $test ) case 'foo' :?> <FONT face="verdana">Foo</FONT> <?case 'bar' :?> <FONT face="verdana">Bar</FONT> <?default :?> <FONT face="verdana">Default</FONT> <?endswitch ;?> If $text is foo, you get all three results. If $text is bar, you get the last two. If it's neither, you get only the last one. Adding breaks would look like this: <?switch ( $test ) :?> <?case 'foo' :?> <FONT face="verdana">Foo</FONT> <?break ;?> <?case 'bar' :?> <FONT face="verdana">Bar</FONT> <?default :?> <?break ;?> <FONT face="verdana">Default</FONT> <?endswitch ;?> or this: <?switch ( $test ) :?> <?case 'foo' :?> <FONT face="verdana">Foo</FONT> <?break ; case 'bar' :?> <FONT face="verdana">Bar</FONT> <?break ; default :?> <FONT face="verdana">Default</FONT> <?endswitch ;?> It may look strange, but it really helps when you have blocks of HTML avoiding lines like: <?}?> http://www.php.net/manual/en/control-structures.switch.php

« previous php.notes (#31588) next »