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!