Get the App
SLTechnology News&Howtos  ›  Development  › 

Where is the PHP process control?

Shulou Source: shulou.com Published: 2022-06-02 10:46:10 10月03日 Update

This article focuses on "where is the PHP process control", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "where is the PHP process control?"

PHP process control is mainly if and switch process control.

When you write code, you often need to perform different actions for different judgments. You can use conditional statements in your code to accomplish this task.

In PHP, the following conditional statements are provided:

If statement-executes code when the condition is established

If...else statement-executes one block of code when the condition is established and another block of code when the condition is not

If...else if....else statement-executes a block of code when one of several conditions is true

Switch statement-executes a block of code when one of several conditions is true

PHP-if statement

The if statement is used to execute code only if the specified condition is established.

Grammar.

If (conditional)

{

Code to be executed when the condition is established

}

If the current time is less than 20, the following example outputs "Have a good day!":

Case study

Run

PHP-if...else statement

To execute one block of code when the condition is established and another block of code when the condition is not, use the if....else statement.

Grammar.

If (conditional)

{

Code executed when the condition is established

}

Else

{

Code executed when the condition does not hold

}

If the current time is less than 20, the following example will output "Have a good day!", otherwise output "Have a good night!":

PHP-if...else if....else statement

To execute a block of code when one of several conditions is true, use the if....else if...else statement. .

Grammar.

If (conditional)

{

Code that executes when the if condition is established

}

Else if (conditional)

{

Code that executes when the elseif condition is established

}

Else

{

Code executed when the condition does not hold

}

The following example outputs "Have a good morning!" if the current time is less than 10, and "Have a good day!" if the current time is not less than 10 and less than 20, otherwise "Have a good night!":

At this point, I believe that everyone has a deeper understanding of "PHP process control", might as well come to the actual operation of it! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Tags: Condition code statement output flow control instance time grammar facet 10% different content learning practical deeper task interest action practicality Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Huawei vpn Shulou Information Shulou Tech Info