前文谈的只是PHP的数据类型,所谓“磨刀不误砍柴功”,打好PHP基础才能更好地学好PHP编程。
PHP中的表达式与运算符与C语言的差别不大,现将其列表于下:
┌─────┬─────────┬──────────┐
│ 符 号 │ 运算符 │ 范 例 │
├─────┼─────────┼──────────┤
│ + │ 加法 │ $a+$b │
├─────┼─────────┼──────────┤
│ - │ 减法 │ $a-$b │
├─────┼─────────┼──────────┤
│ * │ 乘法 │ $a*$b │
├─────┼─────────┼──────────┤
│ / │ 除法 │ $a/$b │
├─────┼─────────┼──────────┤
│ % │ 取余数 │ $a%$b │
├─────┼─────────┼──────────┤
│ ++ │ 递增 │ $a++或++$a │
├─────┼─────────┼──────────┤
│ -- │ 递减 │ $a--或--$a │
├─────┼─────────┼──────────┤
│ == │ 等于 │ $a==10 │
├─────┼─────────┼──────────┤
│ === │ 绝等于 │ $a===10 │
├─────┼─────────┼──────────┤
│ != │ 不等于 │ $a!=10 │
├─────┼─────────┼──────────┤
│ ├─────┼─────────┼──────────┤
│ > │ 大于 │ $a>8 │
├─────┼─────────┼──────────┤
│ ├─────┼─────────┼──────────┤
│ >= │ 大于等于 │ $a>=1 │
├─────┼─────────┼──────────┤
│ = │ 相等赋值运算符 │ $a=0 │
├─────┼─────────┼──────────┤
│ += │ 加法指定运算符 │ $a+=5 │
├─────┼─────────┼──────────┤
│ -= │ 减法指定运算符 │ $a-=1 │
├─────┼─────────┼──────────┤
│ *= │ 乘法指定运算符 │ $a*=2 │
├─────┼─────────┼──────────┤
│ /= │ 除法指定运算符 │ $a/=5 │
├─────┼─────────┼──────────┤
│ %= │ 余数指定运算符 │ $a%=7 │
├─────┼─────────┼──────────┤
│ .= │ 字符串指定运算符│ $a.="hello" │
├─────┼─────────┼──────────┤
│ & │ 与 │ $a&$b │
├─────┼─────────┼──────────┤
│ | │ 或 │ $a|$b │
├─────┼─────────┼──────────┤
│ ^ │ Xor │ $a^$b │
├─────┼─────────┼──────────┤
│ ~ │ 非 │~$a(取1的补码 )│
├─────┼─────────┼──────────┤
│ ├─────┼─────────┼──────────┤
│ >> │ 向右移位 │ $a>>$b │
├─────┼─────────┼──────────┤
│and或&& │ 与 │$a and $b或$a&&$b │
├─────┼─────────┼──────────┤
│or或|| │ 或 │$a or $b或$a||$b │
├─────┼─────────┼──────────┤
│xor │ Xor │ $a xor $b │
├─────┼─────────┼──────────┤
│ ! │ 非 │ !$a │
└─────┴─────────┴──────────┘
┌───┬────────────┐
│符号 │ 意义说明 │
├───┼────────────┤
│ $ │变量 │
├───┼────────────┤
│ & │变量的指针(加在变量前)│
├───┼────────────┤
│-> │对象的方法或属性 │
├───┼────────────┤
│=> │数组的元素值 │
├───┼────────────┤
│? : │三元运算符 │
└───┴────────────┘
同C语言的比较一下吧。其中只是多了个“.”这一个运算符。它的作用是使两个字符串相连,如下例,显示结果为hello,my baby.
$a="hello,";
$b="my baby.";
echo $a.$b;
?>
还有一个符号也使PHP的功能强大了。这就是“$”。它是用于变量之前的,表示这是个变量,如$A,$b等。那它的作用又强在哪呢?这崐就是变量的变量。
如下例:
$a="go";
$$a="here";
echo $a;
echo $$a;
echo $go;
?>
显示结果为:
go
here
here
其实,在一个变量前加一个“$”,就是把这个变量的内容作为了一个新的变量名。这是PHP所特有的,有时可使程序简单化。

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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

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

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.

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),

Dreamweaver CS6
Visual web development tools
