"2014" "Sinsing" "PHP" "Fall" "5" other variable operators

Source: Internet
Author: User
Tags learn php


String operator ******************

1. The string operator is one. This is a point where the left string and the right string are stitched together into a string.

2. For example $ A = "Sin"; $b = "Love Xiao Qian"; So $ A. $b is "Sinsing Yong Love Xiao Qian";

3. We write a xin14.php practice practiced hand:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?php$xing  = "Sinsing everlasting Love"; $qian  = "Xiao Qian"; $msg   =  $xing $qian; Echo   $msg;</span>

4. Then we will find:

5. In fact, this point can not only connect two variables, but also can be two strings of data, that is, $xing. " "Xiao Qian" and "Sinsing Forever Love". Xiao Qian "is also correct.

6. As a matter of fact, the dot is still reviled, because after object-oriented, most languages use the dot as an operator of the calling member method, but because PHP uses it as a string connector, it can only be represented by arrows.

Assignment operator ****************

1. In fact, we have learned that the assignment operator is an equal sign, such as $ A = 3, or a value of 3 to $ A.

2. In fact, the assignment number also has an upgrade version, respectively, is + =,-=, *=,/=,. = These several.

3. What do you mean, $a + = $b; actually equals $ A = $a + $b; In fact, the left is equivalent to the right of a shorthand form.

4. Similarly, $a-= $b; $ A = $a-$b; All the other operators are well understood.

5. Let's try and we'll write a xin15.php to see the effect:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?php$money = 100;//existing capital $money + = 2000;//Sudden outbreak echo $money;</span>

6. Then we look at the effect:

comparison operator *****************

1. The comparison operator is quite interesting, and the operator returns a Boolean type of result, which returns TRUE or false.

2. The comparison operator is mainly divided into > represents less than,<, >= means greater than or equal, <= means less than or equal to the few are well understood.

3. Because the = number is used for assignment, we use = = equals, we use the = = = Three equals sign to mean all equals, that is, not only the value is equal, but also the type must be the same to return true.

4. For unequal situations, we use! = To express, here's! The meaning of "no" means that it is not equal.

5. Our <> also means unequal, because it is a combination of greater than and less than.

6. There is also a symbol,!==, that represents both sides of the comparison operator if the value is not equal, returns True, or if the type is unequal, it returns true, in short, it returns False if the value is equal and the type is the same, otherwise it returns true.

7. Let's take a demo, we'll create a new xin16.php, and write something like this:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?php$i = 4;//Integer 4$f = 4.0;//floating-point number 4.0//determine if $i and $f are equal $flag = $i = = $f; var_dump ($flag);//Determine $i and $f are congruent $flag = $i = = = $f; va R_dump ($flag);</span>

8. The results we have seen are as follows:


Increment decrement operator ******************

1. We use + + to represent the increment operator, that is, the variable's numeric increment 1,--represents the decrement operator, which means that the value of this variable is reduced by 1, which is the first time that C + + was introduced, and because of these two operators, C + + is called C + +.

2. This operator can be used before a variable, or can be used after the variable, that is, $ A + +, and + + $a, are legitimate, and their meaning is the same, is to let the value of the variable plus 1.

3. Maybe a lot of C + + come out of the always like to study the use of this symbol and relish it, in fact, I do not recommend this, the sense of meaning is not very large, we just need to know its purpose.

4. Look at an example xin17.php, our code is as follows:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?php$a = 3; $a ++;++ $a; Echo $a;</span>

5. We have made two self-increases, so its result is certainly 5, the effect is as follows:


Logical operator *****************

1. A logical operator is a logical operation, and its operands are usually of a Boolean type.

2.and is the logic and operation, that is, both sides of the Boolean value is true, the result is true, it is the same as the && effect.

3.or is a logical OR operation, that is, the Boolean value on either side is true, the result of the operation is true, and it and | | The effect is the same.

4.xor is a logical XOR operation, that is, when the values on both sides are different, the result is true, otherwise false.

5.not is a logical non-operator, which is directly reversed, originally true, then false, which is false, then true.

6. Some people will say that and and && are identical, in fact, is not, the key problem is that the priority is different, and for the priority of this kind of thing, I do not recommend that people are too complicated, so we generally do not use to study.

7. Let's write a xin18.php look at the effect:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?php$flag1  = 3==4; $flag 2  = 4==4; $flag 3  = $flag 1 and $flag 2;var_dump ($flag 3);</span>

8. We found the effect as follows:

Trinocular operator *****************

1. Why is it called the trinocular operator? It is also called a ternary operator, because it has three operands.

2. Its format is usually such a a?b:c, it first calculates the condition a, if a is true, then the result of the operator is the value of expression B, if A is false, the result of the operator is the value of the expression C.

3. Let's look at the following code:

<span style= "FONT-FAMILY:KAITI_GB2312;FONT-SIZE:18PX;" ><?php$a = 5; $b = 7; $big = $a > $b? $a: $b, echo $big;</span>

4. The reader should know what I want to do, yes, I just want to find out the bigger one in $ A and $b.

5. So we have the following results:

Summary ***************************

1. In this section we have learned more operators, including assignment operators, comparison operators, and so on.

2. The increment decrement operator, the string operator, and the logical operator are learned later.

3. Finally, there is a classic three-mesh operator.

Track Training **********************

1. Task one: Connect and output the two strings "learn PHP easily" and "learn in combat".

2. Task two: Use the three mesh operator to find the minimum value in 6 and 9.

3. I will not give the demo here, I hope the reader to complete it personally.

"2014" "Sinsing" "PHP" "Fall" "5" other variable operators

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.