Files
freeCodeCamp/guide/chinese/php/conditionals/index.md
Dhiraj Kanchan 8b39e83e24 Fix if statement to use equal to operator instead of assignment operator. (#24522)
Fix if statement to use Double equals (==)  instead of Single equal  (=) which would overwrite the value of $_GET['name'] variable.
2019-01-03 09:52:05 -08:00

1.1 KiB
Raw Blame History

title, localeTitle
title localeTitle
Conditionals 条件语句

条件语句

PHP中的条件语句使用if elseif else语法编写。使用条件允许您根据在运行时提供给页面的不同输入和值执行不同的操作。在PHP中条件通常被称为控制结构。

如果

<?php 
 if ($_GET['name'] == "freecodecamp"){ 
  echo "You viewed the freeCodeCamp Page!"; 
 } 

ELSEIF

<?php 
 if ($_GET['name'] == "freecodecamp"){ 
  echo "You viewed the freeCodeCamp Page!"; 
 } elseif ($_GET['name'] == "freecodecampguide"){ 
  echo "You viewed the freeCodeCamp Guide Page!"; 
 } 

其他

<?php 
 if ($_GET['name'] == "freecodecamp"){ 
  echo "You viewed the freeCodeCamp Page!"; 
 } elseif ($_GET['name'] == "freecodecampguide"){ 
  echo "You viewed the freeCodeCamp Guide Page!"; 
 } else { 
  echo "You viewed a page that does not exist yet!"; 
 } 

注意

如果您有很多可能的条件,您可能想要使用Switch语句

更多信息: