Detailed explanation and examples - double branch structure (with source code)

慕斯
Release: 2023-03-10 08:28:02
Original
2369 people have browsed it

The last article introduced you to "Implementation steps - single branch structure (with source code)". This article continues to introduce you to the double branch structure, so let us continue to learn! ! ! Let's Go!!!

Detailed explanation and examples - double branch structure (with source code)

Double branch structure:

Format 1:

if (conditional statement)

A PHP statement

else

A PHP statement

  • The double branch is to add an else branch based on the single branch

  • If the conditional expression turns out to be true, the first PHP after if will be executed Code

  • If the conditional expression result is false, the first day PHP code after else will be executed

  • The code after if is called if interval or true interval

  • The code after else is called else interval or false interval

Format 2:

if (conditional expression) {

One PHP statement

Two PHP statements

...

}else{

One PHP statement

Two PHP statements

...

}

## If used, generally use the {} format version, because {} is more readable and less likely to be confused, and the functions of format 2 already include the functions of format 1. A PHP statement can be written within {}.

We take the code as an example for the specific format. The code is as follows:

'; else echo '看见他很不爽
'; echo '你懂的?
'; //格式2 $pome = '你知道他是谁吗'; if($pome == '你知道他是谁吗') { echo '风光的背后不是沧桑,是肮脏
'; echo '你身边有奇葩的人吗
'; }else{ echo '没办法,碰到就忍着吧,昂!
'; } ?>
Copy after login

The running results are as follows:

Detailed explanation and examples - double branch structure (with source code)

Recommended learning: "

PHP video tutorial

The above is the detailed content of Detailed explanation and examples - double branch structure (with source code). For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!