Posted by Michael Fesser on 06/24/07 19:37
..oO(severin)
>What is the proper syntax (if exists) for:
>
>switch( $myswitch ){
> case "str1" | "str2" | "str3" | "str4":
> $_th = "user/".$url."/_thumb/".$file;
> break;
>
> default:
> $_th = $gfx."/file.gif";
>}
switch ($myswitch) {
case 'str1':
case 'str2':
case 'str3':
case 'str4':
$_th = "user/$url/_thumb/$file";
break;
default:
$_th = "$gfx/file.gif";
}
If there are just these two possible results, then you could also do it
with a simple in_array() check and a ternary operator (a shortcut for an
if-then-else statement):
$strings = array('str1', 'str2', 'str3', 'str4');
$_th = in_array($myswitch, $strings)
? "user/$url/_thumb/$file"
: "$gfx/file.gif";
Micha
[Back to original message]
|