Home  >  Article  >  Backend Development  >  How to add two numbers in php

How to add two numbers in php

青灯夜游
青灯夜游Original
2022-02-11 16:37:325958browse

php method to add two numbers: 1. Use the " " addition operator, the syntax is "$num1 $num2"; 2. Use the "=" operator to add the variable on the left side of the operator The value of the expression on the right is assigned to the variable on the left, with the syntax "$num1 = $num2".

How to add two numbers in php

The operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

php implements two Number addition

#1. Use the " " addition operator

The " " operator is used for addition calculations.

Example:

<?php
    $a = -100;
    $b = 70;
    echo &#39;$a + $b = &#39;.($a + $b);
?>

How to add two numbers in php

2. Use the "=" operator

"=" plus equals assignment Operator, you can assign the value of the variable on the left side of the operator plus the expression on the right side to the variable on the left

Example:

<?php
header("Content-type:text/html;charset=utf-8");
$a = 100;
$b = 70;
echo &#39;$a += $b 的值为:&#39;.($a += $b);
?>

How to add two numbers in php

Recommended study: " PHP video tutorial

The above is the detailed content of How to add two numbers in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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