Table of Contents
PHP 算术运算符,php算术运算符
arithmetic operators
PHP 算术运算符,php算术运算符
PHP 算术运算符
运算符 | 名称 | 描述 | 实例 | 结果 |
---|---|---|---|---|
x + y | 加 | x 和 y 的和 | 2 + 2 | 4 |
x - y | 减 | x 和 y 的差 | 5 - 2 | 3 |
x * y | 乘 | x 和 y 的积 | 5 * 2 | 10 |
x / y | 除 | x 和 y 的商 | 15 / 5 | 3 |
x % y | 模(除法的余数) | x 除以 y 的余数 | 5 % 2 10 % 8 10 % 2 |
1 2 0 |
- x | 取反 | x 取反 | - 2 | |
a . b | 并置 | 连接两个字符串 | "Hi" . "Ha" | HiHa |
以下实例演示了使用不同算术运算符得到的不同结果:
<?php $x=10; $y=6; echo ($x + $y); // 输出16 echo ($x - $y); // 输出4 echo ($x * $y); // 输出60 echo ($x / $y); // 输出1.6666666666667 echo ($x % $y); // 输出4 ?>
Copy after login
运行
相关阅读:
php strstr 判断一个字符串是否存在于里一个字符串中
php stristr() 函数查找字符串在另一字符串中的第一次出现
php strchr() 函数查找字符串在另一字符串中的第一次出现
php 两个字符串之间的比较函数strncasecmp使用方法详解
php strcasecmp 比较两个字符串是否相等(比较两个字符串的大小)
Statement of this Website
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
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
Assassin's Creed Shadows: Seashell Riddle Solution
4 weeks ago
By DDD
What's New in Windows 11 KB5054979 & How to Fix Update Issues
3 weeks ago
By DDD
Where to find the Crane Control Keycard in Atomfall
4 weeks ago
By DDD
Roblox: Dead Rails - How To Complete Every Challenge
1 months ago
By DDD
Atomfall guide: item locations, quest guides, and tips
1 months ago
By DDD

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)
