note 86283 added to control-structures.switch
| From: | mar dot czapla at gmail dot com | Date: | Fri, 10 Oct 2008 21:17:06 +0000 |
| Subject: | note 86283 added to control-structures.switch | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-145258@lists.php.net to get a copy of this message | ||
<?
/* script 1 */
$foo = "not a number";
switch(false)
{
case "1": { $foo = "1"; break; }
case "2": { $foo = "2"; break; }
default: { $foo = "0"; }
}
echo $foo; // will produce "not a number"
/* script 2 */
$foo = "not a number";
$arr = array("not a number"); // 1 element only !
switch($arr[1]) // element $foo[1] doesn't defined
{
case "1": { $foo = "1"; break; }
case "2": { $foo = "2"; break; }
default: { $foo = "0"; }
}
echo $foo; // will produce "not a number" ( not 0 ! )
/* script 3 */
$foo = "not a number";
$arr = array("not a number"); // 1 element only !
switch($arr[1]?$arr[1]:"1") // element $foo[1] doesn't defined
{
case "1": { $foo = "1"; break; }
case "2": { $foo = "2"; break; }
default: { $foo = "0"; }
}
echo $foo;
// will produce :
// 1 if $arr[1] isn't set
// 1 if $arr[1]=1
// 2 if $arr[1]=2
// 0 if none of above
?>
----
Server IP: 82.177.164.100
Probable Submitter: 80.55.196.98
----
Manual Page -- http://www.php.net/manual/en/control-structures.switch.php
Edit -- https://master.php.net/note/edit/86283
Del: integrated -- https://master.php.net/note/delete/86283/integrated
Del: useless -- https://master.php.net/note/delete/86283/useless
Del: bad code -- https://master.php.net/note/delete/86283/bad+code
Del: spam -- https://master.php.net/note/delete/86283/spam
Del: non-english -- https://master.php.net/note/delete/86283/non-english
Del: in docs -- https://master.php.net/note/delete/86283/in+docs
Del: other reasons-- https://master.php.net/note/delete/86283
Reject -- https://master.php.net/note/reject/86283
Search -- https://master.php.net/manage/user-notes.php