PHP 条件运算符示例
尝试以下示例以了解条件运算符。在test.php文件中复制并粘贴以下PHP程序,并将其保存在您PHP服务器的文档根目录中,然后使用任何浏览器进行浏览。
<html>
<head>
<title>Arithmetical Operators</title>
</head>
<body>
<?php
a = 10;b = 20;
/* If condition is true then assign a to result otheriwse b */
result = (a > b ) ?a :b;
echo "TEST1 : Value of result isresult<br/>";
/* If condition is true then assign a to result otheriwse b */
result = (a < b ) ?a :b;
echo "TEST2 : Value of result isresult<br/>";
?>
</body>
</html>
这将产生以下结果−
TEST1 : Value of result is 20
TEST2 : Value of result is 10