php学习之旅 (3) 语法基础 控制结构

  查看文章 写新文章  
php学习之旅 (3) 语法基础 控制结构
<?php
$d=date("D");
if ($d=="Fri") echo "Have a nice weekend!";
?>


2、if... else

<?php
$d=date("D");
if ($d=="Fri")
   echo "Have a nice weekend!";
else
   echo "Have a nice day!";
?>


//多行代码,用{}

<?php
$d=date("D");
if ($d=="Fri")
   {
   echo "Hello!<br />";
   echo "Have a nice weekend!";
   echo "See you on Monday!";
   }
?>


3、if...elseif....else

<?php
$d=date("D");
if ($d=="Fri")
   echo "Have a nice weekend!";
elseif ($d=="Sun")
   echo "Have a nice Sunday!";
else
   echo "Have a nice day!";
?>


4、switch
<?php
switch ($x)
{
case 1:
   echo "Number 1";
   break;
case 2:
   echo "Number 2";
   break;
case 3:
   echo "Number 3";
   break;
default:
   echo "No number between 1 and 3";
}
?>


分享我的文章 程序员赚钱之路探索

你可能感兴趣的:(PHP,Blog,sun)