Getting to Know Branches in PHP

All programming languages ​​have a branching function, the branching function is used to execute a command under certain conditions, there are several types of branching commonly used, namely:

if statement – ​​Used to execute some code only if a certain condition is true.
if…else statement -Used to execute some code if the condition is true and another code if the condition is false.
if…else if….else statement – ​​Used to select one of many blocks of code to be executed.
switch statement – ​​uses this statement to select one of many blocks of code to be executed
PHP branching

IF STATEMENT

This statement will only execute the program block if the condition is true


if statement
If the above command is executed it will display the words “the condition is now raining”

IF ELSE STATEMENT

This statement will only execute the program block if the condition is true and execute other commands if the condition is false


if else statement
if the script above is executed it will display the string “no rain” because the value of the condition variable is dry.

STATEMENT IF ELSE IF

This statement will execute the program block with the conditions met, if the first block is not met it will check the next condition, here is an example of the syntax:


if else if else statement
If the script above is executed, it will display the string “it’s not hot and it’s not raining” because the value of the condition variable is cloudy. in the following I also make a video tutorial about branching conditions

SWITCH

It’s almost the same as the if else if else condition which will check every block of the program until the condition is met or execute the default syntax, the following is an example of the syntax for using the case