Php-conditional-operator-examples
提供:Dev Guides
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 is $result<br/>";
/*If condition is true then assign a to result otheriwse b*/
$result = ($a < $b ) ? $a :$b;
echo "TEST2 : Value of result is $result<br/>";
?>
</body>
</html>
これは、次の結果を生成します-
TEST1 : Value of result is 20
TEST2 : Value of result is 10