search
Homephp教程php手册PHP移动互联网开发笔记(3)运算符

一、PHP的运算符

PHP中有丰富的运算符集,它们中大部分直接来自于C语言。按照不同功能区分,运算符可以分为:算术运算符、字符串运算符、赋值运算符、位运算符、条件运算符,以及逻辑运算符等。当各种运算符在同一个表达式中时,它们的运算是有一定的优先级的。

(1)算术运算

+    -   *   /  %  ++ --

(2)字符串运算符

字符串运算符只有一个.(点)就是英文的句号。它可以将字符串连接起来,组成新字符串,也可以将字符串与数字连接,这时类型会自动转换。

	$a="dawanganban";  
$b="123";  
echo $a.$b;   //输出结果:dawanganban123  
(3)赋值运算符
	= += -= *= /= %= .=



$a="dawanganban";  
$a.=1;  
$a.=2;  
$a.=3;  
echo $a.$b;   //输出结果:dawanganban123  
(4)位运算符

 

& ~ ^ >

(5)比较运算符

> = === !==

:为不等于和!=相同

===:恒等,值相等且类型一致

!==:非恒等,值不相等或类型不一致

  1. 	echo 5 == "5"; //true  PHP是弱类型语言(js中的变量类似)  
    echo 5 === "5";  //false  完全等于  
(6)逻辑运算

AND(逻辑与) OR(逻辑或) XOR(逻辑异或) &&(逻辑与) (逻辑或) !(逻辑非)

	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  
 



Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

EditPlus Chinese cracked version

EditPlus Chinese cracked version

Small size, syntax highlighting, does not support code prompt function

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor