note 86283 deleted from control-structures.switch by crell
| From: | crell@php.net | Date: | Mon, 27 Jun 2022 20:58:26 +0000 |
| Subject: | note 86283 deleted from control-structures.switch by crell | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-218642@lists.php.net to get a copy of this message | ||
Note Submitter: mar dot czapla at gmail dot com
----
<?php
/* 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
?>