<?
/* 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
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.