How to add two numbers in php

青灯夜游
Release: 2023-03-15 09:44:02
Original
5961 people have browsed it

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);
?>
Copy after login

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);
?>
Copy after login

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!

Related labels:
php
source:php.cn
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template