Home  >  Article  >  Backend Development  >  PHP conditional statements and ternary operators

PHP conditional statements and ternary operators

巴扎黑
巴扎黑Original
2016-11-09 13:47:471285browse

<?php
$n1=1000;
$n2=1000;
$n3=100;
$n4=100;
// if 语句 - 如果指定条件为真,则执行代码
// if...else 语句 - 如果条件为 true,则执行代码;如果条件为 false,则执行另一端代码
// if...elseif....else 语句 - 选择若干段代码块之一来执行
// switch 语句 - 语句多个代码块之一来执行
//条件判断语句
if($n1==$n2)echo &#39;true&#39;;else echo &#39;false&#39;;
echo &#39;<br>&#39;;
// 三元运算符不是一种必不可少的结构,但却是一种美化代码的途径。
// 同样,它可以取代不好的if…else代码块,并且可以提高代码的可读性。
//三元运算符
echo $str = $n3==$n4?&#39;true&#39;:&#39;false&#39;;
//输出 true true
?>

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:Output thumbnail addressNext article:Output thumbnail address