Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use PHP Branch structure ifelseif

Shulou Source: shulou.com Published: 2022-06-01 13:10:50 10月01日 Update

This article will explain in detail how to use the PHP branch structure ifelseif. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

PHP branching structure ifelseif

Syntax:

If (conditional expression 1) {

Code that runs under condition 2

} elseif (conditional expression 2) {

Code that runs under condition 2

} elseif (conditional expression n) {

Code that meets condition n to run

} [else] {

The running code that none of the above has achieved

}

Example: dogs and cats, get the number by random number, if the dog is larger than the cat, one mouth of cat hair; if the dog is smaller than the cat, one mouth of dog hair.

If equal, cat and dog fight.

$dag = rand (1100); $cat = rand (1100); if ($dog > $cat) {echo 'cat hair';} elseif ($dog < $cat) {echo 'dog hair';} else {echo 'cat-and-dog war' } this is the end of the article on "how to use PHP branch structure ifelseif". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Conditions code runs branches structures articles expressions wars more good practical content quantity articles cases knowledge grammar random numbers references help Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia Linux MySQL vpn Docker