PHP学习笔记3-逻辑运算符

逻辑运算符图解:

PHP学习笔记3-逻辑运算符_第1张图片

 

逻辑且&&:

 1 php
 2 /**
 3  * Created by PhpStorm.
 4  * User: Administrator
 5  * Date: 2015/6/26
 6  * Time: 18:55
 7  */
 8 function traceNum(){
 9     for($i=0;$i<=100;$i++){
10         if($i%2==0 && $i%3==0){ //%:求余;输出能同时被2和3整除的数;
11             echo $i."
"; 12 } 13 } 14 } 15 traceNum();

逻辑或||:

 1 php
 2 /**
 3  * Created by PhpStorm.
 4  * User: Administrator
 5  * Date: 2015/6/26
 6  * Time: 18:55
 7  */
 8 function traceNum2(){
 9     for($j=0;$j<=100;$j++){
10         if($j%2==0 || $j%3==0){//输出能被2整除或被3整除的数;
11             echo $j."
"; 12 } 13 } 14 } 15 traceNum2();

逻辑非!:

 1 php
 2 /**
 3  * Created by PhpStorm.
 4  * User: Administrator
 5  * Date: 2015/6/26
 6  * Time: 18:55
 7  */
 8 function traceNum3(){
 9     for($m=0;$m<=100;$m++){
10         if($m%2!=0){//输出奇数;
11             echo $m."
"; 12 } 13 } 14 } 15 traceNum3();

 

转载于:https://www.cnblogs.com/Vito-L/p/4603996.html

你可能感兴趣的:(php,开发工具)