php if else syntax of process control
if and else grammar
This is a very important section is also an important PHP syntax among.
[Note] I define the level of this syntax is: dictation level. That is you need, eyes closed, we are able to write something. Linear motor parameters
English explanation:
* if * pronunciation: [ɪf]
Chinese explanation: if
else pronunciation: [ɛls]
Chinese explanation: otherwise
We will if and if ... else combined into four basic grammar, each of which must back down.
<? PHP IF (Boolean condition) to perform a Boolean value is true (true), can only write a single line of code; ?> <PHP? IF (Boolean condition) to perform a Boolean value is true (true), can only write one line of code; else perform a Boolean value false (false), you can only write a single line of code; ?>
<PHP? IF (Boolean condition) { executes boolean value True (true), write lines of code; } ?> <PHP? IF (Boolean condition) { executes boolean value True (true), a multi-writable line; } {the else performs the Boolean value false (false), write lines of code; } >?
Many people like to buy lottery tickets, we take the process Gambling show to write if example.
? <PHP // definition of what winning variable, the variable is true, represent a winning $ zhongjiang = to true; // Since $ zhongjiang result is true, it shows: "buy a house" // be changed to try false execution result, if false, then, does not perform echo 'buy a house'; IF ($ Zhongjiang) { echo 'buy a house'; } // succeeding code echo 'why why'; ?>
In the "Book of Changes 3.2.2 Boolean is knowledge" with you to make this chapter a wretched example:
For example television drama series often talk about the sentence:
If the beautiful sister (guy) is my bubble at hand, I'm dead willing.
We take a look at is the flow chart look like this:
You can write this sentence with the code of the computer:
If I soak into the beautiful sister
is: I am willing to die
if there is no bubble to
you: I do not want to die
If you press the flowchart of view, then is this:
The above example, we can use if ... else ... translated into code:
? <PHP // we define a bubble to the beauty of the variable ($ pao) is false, meaning no bubble to $ PAO = false; IF ($ pao) // you can try here to write multiple lines of code will not error. echo 'I am willing to die'; the else echo 'I do not want to die'; //if...else execution ends, follow the code ?> in the if ...
else, we can write a use braces, multiple words example:
? <PHP // we define a bubble to the beauty of the variable ($ pao) is true, meaning the bubble to $ PAO = to true; IF ($ pao) { echo 'I am willing to die'; echo 'Lin Chi-ling, I love is you. '; } The else { echo' I do not want to die '; echo' Xifeng, I would not love you '; } //if...else execution ends, subsequent code >?