PHP学习之PHP运算符_php基础
PHP运算符
下面我分别看一下PHP3的算术、字符串、逻辑与比较等运算符。
1、算术运算符
+: $a + $b 加 $a加上$b -: $a - $b 减 $a减去$b *: $a * $b 乘 $a乘以$b /: $a / $b 除 $a除以$b %: $a % $b 取模 $a除以$b的余数 如果两个操作数都是整型值(字符串将被转换为整型值),除号("/") 返回整型值(整除的值)。如果任一个操作数是浮点值,则做浮点除法。
2 字符串运算符
字符串操作符只有字符串连接符 (".")。 $a = "Hello "; $b = $a . "World!"; // now $b = "Hello World!"
3、赋值运算符
基本的赋值运算符是 "="。 一个赋值表达式的值就是所赋给的值。例如, 表达式 $a = 3 的值是3。 这允许你这样做一些复杂的事情: $a = ($b = 4) + 5; // 现在 $a 等于 9, $b为4 。 除了基本赋值符外,还有"复合运算符"。对于所有的二进制数和字符串,允许你做变量自我复合运算。
例如: =: $a = 3; +=:$a += 5; // 把$a 设成 8, 也就是: $a = $a + 5; $b = "Hello "; . :$b .= "There!"; // 把 $b 设成 "Hello There!", 就象 $b = $b . "There!";
4、 位运算符
位运算允许你对指定的数据置位或复位。 &:与运算,$a & $b 与 $a和$b都被置位则结果被置位 |:或运算,$a | $b 或 $a或$b有一个被置位则结果被置位 ~:非运算,~ $a 非 $a没有被置位则结果被置位
5、 逻辑运算符
and: $a and $b 与 $a和$b同时为真则结果为真 or : $a or $b 或 $a或$b有一个为真则结果为真 xor: $a xor $b 异或 $a和$b不同时为真则结果为真 ! : ! $a 非 $a为假则结果为真 &&: $a && $b 与 $a和$b同时为真则结果为真 ||: $a || $b 或 $a或$b有一个为真则结果为真 比较两个变量时,"与"和"或"运算有两种运算符这是以为两种运算符有不同的优先级 6、 比较运算符 比较运算符,就象名字一样,允许你比较两个值。 ==: $a == $b 等于 $a等于$b结果为真 !=: $a != $b 不等于 $a不等于$b结果为真 : $a > $b 大于 $a大于$b结果为真 =: $a >= $b 大于等于 $a大于或等于$b结果为真

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

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

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

PHP logging is essential for monitoring and debugging web applications, as well as capturing critical events, errors, and runtime behavior. It provides valuable insights into system performance, helps identify issues, and supports faster troubleshoot

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Alipay PHP...

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
