php - 在php中连接两个整数

标签 php

我知道在 php 中可以像这样连接两个字符串

$a .= $b;

等于

$a = $a . $b;

是否可以用整数做某事?但是用数学运算?我有两个变量:

$var1 = 8;
$var2 = 2;

我需要执行 $var1 - $var2,但我不想创建第三个变量来保存此计算。我会尝试 $var1 = $var1 + $var2 这行得通吗?是否有另一种 .= 类似的方法?

最佳答案

好吧,因为现在大家都很困惑

// _Appending_ $var2 to $var1 and assign it to $var1
$var1 .= $var2;
// _Add_ $var2 to $var1 and assign the result to $var1
$var1 += $var2;

没有什么比每个 binary operator is combineable with the assignment 更值得记住的了。 .在引擎中,它总是扩展为

$var1 = $var1 . $var2; // You can imagine how the others looks like

In addition to the basic assignment operator, there are "combined operators" for all of the binary arithmetic, array union and string operators that allow you to use a value in an expression and then set its value to the result of that expression.

关于php - 在php中连接两个整数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12109925/

相关文章:

php - PDO:调用创建临时表的mysql存储过程,然后从中选择

php - 如果 WooCommerce 3+ 中的购物车页面上的购物车已清空,则重定向到商店

php - 使用 ImageMagick (PHP) 将 2 张并排的图像合并为 1 张

php - Paypal 专业版 : is it necessary to gather details oneself or can PayPal do that for me?

javascript - HTML+JQUERY <标签> 已移动

php - Laravel:在 PDO 对象上指定了不受支持的属性。 Ubuntu 上的 MSSQL

php - 使用 MySQL + PHP 更新多个变量

Javascript - Jquery 不显示表单中传递的值

php - 如何使用 PHP 将文件从一个目录复制到另一个目录?

php - 项目研究 - 可缩放、可滚动、可悬停的高分辨率图像