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

慕斯
Release: 2023-03-10 08:28:02
Original
2458 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:

<?php 
/******双项分支结构 ******/
//定义一个变量
$pome = &#39;有一个奇葩&#39;;
if($pome == &#39;有一个奇葩&#39;)
       echo &#39;在我周围有一个从未见过的厚颜无耻之人<br/>&#39;;
    else 
       echo &#39;看见他很不爽<br/>&#39;;
       echo &#39;你懂的?<br/>&#39;;
       

       //格式2
 $pome = &#39;你知道他是谁吗&#39;;
 if($pome == &#39;你知道他是谁吗&#39;)   {
     echo &#39;风光的背后不是沧桑,是肮脏<br/>&#39;;
     echo &#39;你身边有奇葩的人吗<br/>&#39;;
 }else{
     echo &#39;没办法,碰到就忍着吧,昂!<br/>&#39;;
 }   
?>
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
Popular Tutorials
More>
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!