PHP的三种类型的运算符
运算符是可以通过给出的一或多个值(用编程行话来说,表达式)来产生另一个值(因而整个结构成为一个表达式)的东西。
第一种是一元运算符,只运算一个值,例如 !(取反运算符)或 ++(加一运算符)。
例子
1、++i 的用法(以 a=++i ,i=2 为例)
先将 i 值加 1 (也就是 i=i+1 ),然后赋给变量 a (也就是 a=i ),
则最终 a 值等于 3 , i 值等于 3 。
所以 a=++i 相当于 i=i+1 ,a=i
2、i++ 的用法(以 a=i++ ,i=2 为例)
先将 i 值赋给变量 a (也就是 a=i ),然后 i 值加 1 (也就是 i=i+1 ),
则最终 a 值等于 2 ,i 值等于 3 。
所以 a=i++ 相当于 a=i , i=i+1
3、++i 与 i++
a=++i 相当于 i++ , a=i
a=i++ 相当于 a=i , i++
4、++i 与 i++ 单独使用时,相当于 i=i+1
如果赋给一个新变量,则 ++i 先将 i 值加 1 ,而 i++ 先将 i 赋给新变量
第二种是二元运算符,可接受两个值,例如熟悉的算术运算符 +(加)和 -(减),大多数 PHP 运算符都是这种
$a =1+2;
$b =3-1;
第三种是三元运算符,可接受三个值,它应该被用来根据一个表达式在另两个表达式中选择一个,而不是用来在两个语句或者程序路线中选择。(也可称之为条件运算符可能更合适)
代码格式如下:(expr1) ? (expr2) : (expr3);
例如:$page = !empty( $_GET['page'] ) ? $_GET['page'] : 1;

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

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.

Atom editor mac version download
The most popular open source editor