PHP Mobile Internet Development Notes (3)--operator

Source: Internet
Author: User
Tags arithmetic arithmetic operators bitwise bitwise operators logical operators php operator string

First, the PHP operator

PHP has a rich set of operators, most of which come directly from the C language. The operators can be divided into arithmetic operators, string operators, assignment operators, bitwise operators, conditional operators, and logical operators, according to different functions. When the various operators are in the same expression, their operations are given a certain degree of precedence.

(1) Arithmetic operation

+    -   *   /  %  ++ --

(2) string operator

There is only one string operator. (point) is the end of English. It can concatenate strings, form a new string, or concatenate a string with a number, when the type is automatically converted.

	$a = "Dawanganban";  
$b = "123";  
echo $a. $b;   Output Result: dawanganban123  
(3) Assignment operator
	= + = = *=/=%=. =

$a = "Dawanganban";  
$a. =1;  
$a. =2;  
$a. =3;  
echo $a. $b;   Output Result: dawanganban123  
(4) Bitwise operator & ~ ^ << >>

(5) Comparison operators

> < >= <= = =!= <> = =!==

<>: For not equal to and! = Same

= =: identity, value equal and type consistent

! = =: Non-identity, unequal value or inconsistent type

    1. 	echo 5 = "5"; True  PHP is a weakly typed language (similar to a variable in JS)  
      echo 5 = = "5";  False is  exactly equal to  
(6) Logical operation

and (logical vs.) or (logical OR) XOR (logical XOR) && (Logic and) (logic or)! (Logical non)

	Var_dump (5 && "");   False  
Var_dump (5 && "2");//true  
var_dump (5  "");//true  
var_dump (0 xor 1);//true  
Var_dump (0 xor 0); False  
Var_dump (1 xor 1);//false  

Related Article

Beyond APAC's No.1 Cloud

19.6% IaaS Market Share in Asia Pacific - Gartner IT Service report, 2018

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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: and provide relevant evidence. A staff member will contact you within 5 working days.