逻辑运算符图解:
逻辑且&&:
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."<br/>"; 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."<br/>"; 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."<br/>"; 12 } 13 } 14 } 15 traceNum3();
时间: 2024-10-13 18:20:48