Files
freeCodeCamp/guide/russian/php/conditionals/index.md
2019-03-22 00:47:13 +04:00

51 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: Conditionals
localeTitle: Условные операторы
---
## Условные операторы
Условные операторы в PHP используют синтаксис `if` , `elseif` , `else`. Использование условных операторов позволяет выполнять различные действия в зависимости от разных входных значений, предоставляемых на странице во время выполнения. В PHP условные операторы часто называются управляющими конструкциями.
### If
```PHP
<?php
if ($_GET['name'] == "freecodecamp"){
echo "You viewed the freeCodeCamp Page!";
}
```
### Elseif
```PHP
<?php
if ($_GET['name'] == "freecodecamp"){
echo "You viewed the freeCodeCamp Page!";
} elseif ($_GET['name'] == "freecodecampguide"){
echo "You viewed the freeCodeCamp Guide Page!";
}
```
### Else
```PHP
<?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](/php/switch).
#### Дополнительная информация:
* [Руководство по управлению структурой php.net](https://secure.php.net/manual/en/control-structures.elseif.php)