PHP conditional control statement-"if statement" example

Source: Internet
Author: User
In all programming languages, such as C language. JAVA and so on, all have the existence of if statements, of course, also include PHP. The if statement is used to select and execute different code snippets according to the conditions. If statement

In all programming languages, such as C language. JAVA and so on, all have the existence of if statements, of course, also include PHP. The if statement is used to select and execute different code snippets according to the conditions.

Let's take a look.If statement format

If (expression) PHP statement;

If the expression is true, run the PHP statement. Otherwise, the statement will be skipped and executed.

If more than one statement is executed, we can use "{}" to pack it, as shown below:

If (expression) {PHP statement 1; PHP statement 2; PHP statement 3 ;}

The "{}" statement is called a statement group.

Take a lookIf statement control process

Let's take a look at it.Example of if statementThe code is as follows:

 $ Num is an even number ";}?>

Example:

First, use the rand () function to generate a number between and 50, and then judge whether the number is an even number. if it is an even number, the result is output. Otherwise, nothing is output.

Because it is a random number, sometimes it is not an even number, it will not appear now. In this case, we usually have a PHP statement executed when the conditions are not met. This requires the content in the next section, let's talk about "if..." in the PHP condition control statement... else statement

The above is a detailed description of the "if statement" instance of the PHP conditional control statement. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.