帝国常用的PHP判断语法集合
帝国常用的PHP判断语法集合包括:if语句、else语句、elseif语句、switch语句等。其中,if语句用于判断一个条件是否成立,如果成立则执行相应的代码块;else语句用于在if语句的条件不成立时执行相应的代码块;elseif语句用于在多个条件中选择一个符合条件的代码块执行;switch语句用于根据不同的条件执行不同的代码块。这些判断语法可以帮助我们更好地控制程序的流程,实现更加灵活和高效的编程。
默认内容页帝国CMS判断方法
1 | <?phpif( $navinfor [befrom]){?><p>来源:[!--befrom--]</p><?php}?> |
利用PHP语法输出判断结果
1 | <?phpif( $navinfor [befrom]){ echo "来源:" . $navinfor [befrom];}?> |
1 | <?phpif( $navinfor [befrom]){ echo "来源:" .ReplaceBefrom( $navinfor [befrom]);}?> |
结合if else来使用
1 | <?phpif( $navinfor [ 'befrom' ]){?><p>[!--befrom--]</p><?php} else {?>菜鸡源码<?php}?> |
emptye的方法
1 | <?phpif(! empty ( $classr [classimg])){ echo '<imgsrc="' . $classr [classimg]. '">' ;} else { echo '' ;}?> |
注释:!(为不)+empty(为空)=!empty(不为空)
各种判断调用作者的方法
1 | <?=ReplaceBefrom( $navinfor [befrom]? $navinfor [befrom]: '菜鸡源码' )?><?= $navinfor [befrom]? '来源:' . $navinfor [befrom]. '' : '' ?><?= $navinfor [befrom]? "来源:$navinfor[befrom] " : "" ?>注释: 为空格<?= $navinfor [befrom]? $navinfor [befrom]: "暂无简介" ?><? echo $navinfor [ 'befrom' ]? '<span>来源:' . $navinfor [befrom]. '</span>' : '暂无来源' ;?><?= $navinfor [writer]?: "暂" ?> |
switch判断方法
1 | <?phpswitch( $class_r [ $GLOBALS [navclassid]][ 'bname' ]){ case "国内" : $sid =34; break ; case "国际" : $sid =35; break ; default : $sid =34;}?><?= $sid ?> |
包括多值时的判断
1 | <?php $c1_r = array (35,34); $c2_r = array (36,37); if (in_array( $GLOBALS [navclassid], $c1_r )){ $cid1 = '广告1' ;} elseif (in_array( $GLOBALS [navclassid], $c2_r )){ $cid1 = '广告2' ;} else { $cid1 = '其他广告' ;}?><?= $cid1 ?> |
或直接输出:把 $cid1 =改为 echo