Arithmetic expressions are used in several situations:

* arithmetic evaluation command
* arithmetic expansion
* substring parameter expansion
* the ''let'' builtin command
* C-style for loop
* array indexing
* conditional expressions
* Assignment statements, and arguments to declaration commands of variables with the integer attribute.

Arithmetic expressions are used in several situations:

* arithmetic evaluation command
* arithmetic expansion
* substring parameter expansion
* the ''let'' builtin command
* C-style for loop
* array indexing
* conditional expressions

$(( ))

$[ ]

The arithmetic expression is evaluated and expands to the result. The output of the arithmetic expansion is guaranteed to be one word and a digit in Bash.

Please do not use the second form $[ ... ]! It's deprecated. The preferred and standardized form is $(( ... ))!

$(( ))

$[ ]

The arithmetic expression is evaluated and the resulting value replaces the whole $((...)) construct:

Please do not use the second form $[ ... ]! It's deprecated. The preferred and standardized form is $(( ... ))!

Synopsis

let

Description

The let builtin command evaluates the arithmetic expression and returns the exit codes

* 0 (TRUE) when evaluated to not 0 (arithmetic "true")
* 1 (FALSE) when evaluated to 0 (arithmetic "false")

Synopsis

let arg [arg ...]

Description

The let builtin command evaluates each supplied word from left to right as an arithmetic expression and returns an exit code according to the truth value of the rightmost expression.

* 0 (TRUE) when arg evaluated to not 0 (arithmetic "true")
* 1 (FALSE) when arg evaluated to 0 (arithmetic "false")

Synopsis

(( ))

Description

This command evaluates the arithmetic expression .

If the expression evaluates to 0 then the exit code of the expression is set to 1 (FALSE). If the expression evaluates to something else than 0, then the exit code of the expression is set to 0 (TRUE). For this return code mapping, please see this section.

There are limits set for the arithmetic evaluation capabilities of the bash shell. The manual is succinct about this aspect of shell arithmetic but states:

Evaluation is done in fixed-width integers with no check for overflow,
though division by 0 is trapped and flagged as an error.

PHP arithmetic operators
Today we will lear about aritmetic operators for PHP.
These are the arithmetic operators, below also a simple example, using the sum operator, to perform a simple sum of three numbers.
<!--break-->