A. String Insertion
To provide maximum flexibility for developers to handle string values, PHP provides a literal insert and content insertion
A method.
Double quotation marks provide maximum flexibility because both the variable and the transfer sequence are parsed accordingly.
Copy CodeThe code is as follows:
$userName = "Zhang San";
echo "His name is $userName";
echo "
";
There are some problems in Chinese
echo "His name is $username, he is 19 years old, has grown up!" ";
echo "
";
Can be solved by a string connection
echo "His name is" $userName. "He's 19 years old and he's grown up! "
Escape characters can be parsed
echo "Although his QQ number has a lot of girls, \ n But one does not belong to him";
?>
Some of the commonly used escape characters
Escape sequence Description
\ n line break
\ r Enter
\ t Horizontal Tabulation Chart
\ \ counter Slash
\$ dollar Symbol
\ "Double quotation marks
Single quotes are interpreted as they are declared, and when parsing a string, neither the variable nor the escape sequence is parsed.
echo ' Wu Qi variable name: $userName, escape character \ n is invalid in single quote '
?>
two. Operator
Operators are symbols used to perform some sort of operation on arrays and variables.
Arithmetic operators
Compound assignment operator
Forward increment decrement and post increment decrement operators:
$a =++ $b;
$a = $b + +;
$a =--$b;
$a = $b--;
Comparison operators
Operator name Example
+ Plus $a+ $b
-Reduced $a-$b
* Take $a* $b
/except $a/$b
% residual $a% $b
Operator usage is equivalent to
+ = $a + = $b $a = $a + $b
-= $a-= $b $a = $a-$b
*= $a *= $b $a = $a * $b
/= $a/= $b $a = $a/$b
%= $a%= $b $a = $a% $b
. = $a. = $b $a = $a. $b
How to use operator names
= = equals $a= = $b
= = = Identity $a= = = $b
! = Unequal $a!= $b
! = = Not identical $a!= = $b
<> Unequal $a<> $b
< less than $a< $b
> Greater than $a> $b
<= is less than or equal to $a<= $b
>= is greater than or equal to $a>= $b
Note: Identity means that only the operands on both sides are equal and the data type is equivalent to return true;
For example: 0 = = "0" This return is true because the operands are equal
0= = = "0" This return is false because the data type is different
logical operators
! No, $b.
If $b is false, the
Returns true;
&& and $a&& $b
If $ A and $b are both
True, the result is true;
False otherwise
|| or $a| | $b
If $ A and $b have a
One for true or both for
True, the result is
true; False otherwise
And with $ A and $b
Same as &&, but its excellent
Lower First level
Or or $ A or $b
with | | Same, but its priority
Lower level
Operator "and" and "or" than && and | | The priority level is lower.
Ternary operator
Condition? Value if True:value if False
Example: ($grade >=50? "Passed": "Failed")
Error suppression operators:
$a =@ (57/0);
The divisor cannot be 0, and error occurs, so add @ To avoid an error warning.
Array operators
+ Union! $b
Returns a containing
$a and $b all the meta
Array of Vegetarian
= = equivalent $a&& $b
If $ A and $b have
The same element, which returns
True
= = = Identity $a| | $b
If $ A and $b have
The same elements as well as
In the same order, return
True
! = Non-equivalent $ A and $b
If $ A and $b are not
Equivalent, returns True
<> Non-equivalence
If $ A and $b are not
Equivalent, returns True
! = = Non-identity $ A or $b
If $ A and $b are not
Identical, returns True
Precedence and associativity of operators:
Generally, operators have a set of precedence, that is, the order in which they are executed.
Operators also have associativity, which is the order in which operators of the same precedence are executed. This order usually has the
Left to right, right to left, or irrelevant.
The table for operator precedence is given below. The top operator has the lowest priority, as the table's top-down
Order, priority increments.
Operator Precedence
Left
Left or
Left XOR
Left and
Right print
Left
= + = = *=/=. =%= &= |= ^= ~= <<=
>>=
Left? :
Left | |
Left &&
Left |
Left ^
Left &
irrelevant = = = = = = = = = =
Unrelated <<= >>=
Left << >>
Left +-.
Left */%
Right
! ~ ++ --
(int) (double) (string) (array) (object) @
Right []
Not relevant new
Not relevant ()
To avoid priority confusion, you can use parentheses to avoid precedence.
Three Control structure
If we want to effectively input the corresponding user, the code needs to have the ability to judge. The ability to make a program judge
Structure is called a condition.
If
Conditional Judgment Statement
if (conditional judgment) {
//......
}
if (conditional judgment) {
//....
}
else {
//....
}
if (conditional judgment) {
//...
}
Left | |
Left &&
Left |
Left ^
Left &
irrelevant = = = = = = = = = =
Unrelated <<= >>=
Left << >>
Left +-.
Left */%
Right
! ~ ++ --
(int) (double) (string) (array) (object) @
Right []
Not relevant new
Not relevant
ElseIf {
//...
}
ElseIf {
//....
}
else {
//....
}
Switch
Statement
Switch (variable) {
Case "Value 1":
//...
Break
Case "Value 2":
//...
Break
Case "Value N":
//...
Break
Default
//....
Break
}
While
Cycle
while (condition) {
//....
}
For
Cycle
for (initial value; condition; counter) {
//....
}
In addition to the For Loop, PHP provides a foreach loop that is dedicated to the use of arrays. We are counting
This is described in detail in the group.
Do
While
Cycle
do {
//...
} while (condition);
If you want to stop the execution of a piece of code, depending on the effect you need to achieve, there are 3 ways to implement it.
The first type: break; Exit the loop; the second is exit; the third type of exit procedure is continue; exit the current
Ring
if (condition)
{
Break Continue
}
http://www.bkjia.com/PHPjc/324037.html www.bkjia.com true http://www.bkjia.com/PHPjc/324037.html techarticle A. string insertion to provide maximum flexibility for developers to handle string values, PHP provides a way to literally insert and insert content. Double quotes provide maximum flexibility ...