PHP基础知识运算符
<?php
/**
* Created by PhpStorm.
* User: 刘高洋
* Date: 2016/7/14
* Time: 16:22
*/
header ( "Content-type:text/html;charset=utf-8" );
$a = 100 ;
$b = 50 ;
echo "a + b=" . ( $a + $b ) . "<br>" ;
if ( $a > 10 && $b > 10 ) {
echo "a和b都大于10" . "<br>" ;
}
else {
echo "a和b都小于10" . "<br>" ;
}
* Created by PhpStorm.
* User: 刘高洋
* Date: 2016/7/14
* Time: 16:22
*/
header ( "Content-type:text/html;charset=utf-8" );
$a = 100 ;
$b = 50 ;
echo "a + b=" . ( $a + $b ) . "<br>" ;
if ( $a > 10 && $b > 10 ) {
echo "a和b都大于10" . "<br>" ;
}
else {
echo "a和b都小于10" . "<br>" ;
}
//三目运算符:
//例子1
$c
=
60
;
$v = ( $c == 50 ) ? "真值" : "假值" ;
echo $v ;
$v = ( $c == 50 ) ? "真值" : "假值" ;
echo $v ;
echo"<br>";
//例子2
$e
=
true
;
$value = $e ? "e为真" : "e为假" ;
echo $value ;
$value = $e ? "e为真" : "e为假" ;
echo $value ;
//switch运算符
$myNumber = 50 ;
switch ( $myNumber ) {
case 10 :
echo 10 ;
break ;
case 50 :
echo 50 ;
break ;
case 90 :
echo 90 ;
break ;
default :
echo "不存在" ;
break ;
}
echo "<br>" ;
//九九乘法表
for ( $v = 1 ; $v < 10 ; $v ++) {
for ( $b = 1 ; $b <= $v ; $b ++) {
$myNumber = 50 ;
switch ( $myNumber ) {
case 10 :
echo 10 ;
break ;
case 50 :
echo 50 ;
break ;
case 90 :
echo 90 ;
break ;
default :
echo "不存在" ;
break ;
}
echo "<br>" ;
//九九乘法表
for ( $v = 1 ; $v < 10 ; $v ++) {
for ( $b = 1 ; $b <= $v ; $b ++) {
echo $b . "*" . $v . "=" . $v * $b . " ";
}
echo "<br>" ;
}
echo "<br>" ;
}