# Operators

## Arithmetic operators

Do you remember elementary arithmetics from school? Arithmetic operators allow you to perform elementary arithmetics and additional calculations.

Example Name Result

$_a+$_b

Sum of$_aplus$_b

$_a-$_b

Subtraction

Difference between$_aand$_b

$_a*$_b

Multiplication

Product of$_aand$_b

$_a/$_b

Division

Quotient of$_aand$_b

$_a%$_b

Modulus

Remainder of$_adivided by$_b

$_a*$_b

Power

$_ais the base and$_bthe exponent.
Thus, the result is the power of$_a. ## Assignment operators The most basic assignment operator is "=". One might assume that it stands for "equals". However, this is not the case. Instead, this operator means that the value of the expression on the right is assigned to the operand on the left. Thus, the expression should be read as "is set to the value of". ### Single-line code block ``````{%$_a = 3 %}
{% $_a += 5 %} {%$_b = "Hello " %}
{% $_b .= "there!" %} `````` ### Multi-line code block ``````{%$_a = 3;
$_a += 5; # sets$_a to the value 8 as if we had written: $_a =$_a + 5

$_b = "Hello ";$_b .= "there!";

# sets $b to the value "Hello there!" %}`````` Example Name Result$_a=$_b Assignment$_acontains the value of$_b$_a.=$_b Union A string is extended to include the string in$_b.

$_a+=$_b

Is equivalent to$_a=$_a+$_b$_a-=$_b Subtraction Is equivalent to$_a=$_a-$_b

$_a*=$_b

Multiplication

Is equivalent to$_a=$_a*$_b$_a/=$_b Division Is equivalent to$_a=$_a/$_b

$_a%=$_b

Modulus

Is equivalent to$_a=$_a%$_b ## Relational operators Example Name Result$_a==$_b equal Returns TRUE if$_aequals$_b.$_a===$_b identical Returns TRUE if$_aequals$_band they are of the same type.$_a!=$_b unequal Returns TRUE if$_adoes not equal$_b.$_a!==$_b not identical Returns TRUE if$_adoes not equal$_bor if they are not of the same type.$_a<$_b less than Returns TRUE if$_ais less than$_b.$_a>$_b greater than Returns TRUE if$_ais greater than$_b.$_a<=$_b less than or equal to Returns TRUE if$_ais less than or equal to$_b.$_a>=$_b greater than or equal to Returns TRUE if$_ais greater than or equal to$_b. ## Logical operators Example Name Result$_a&&$_b and TRUE if both$_aand$_bare TRUE.$_a

$_b or TRUE if at least one of the values of$_aand$_bis TRUE. !$_a

If more than one logical operator is used within a condition, && operators take precedence over || operators. You can change this order by inserting brackets:

``````{%
if( ($_a==$_b || $_a==$_c) && $_c !=$_d )
{

}
%}``````

## Union operators

The union operator "." concatenates any number of strings, number values, variables and return values of functions to a single string.

Example Name Result

$_a.$_b.$_c Union The strings$_a,$_band$_care concatenated.

``````{%
$_text1 = ["Hello ", "there", "!"]; print ($_text1 . $_text1 .$_text1 );
# returns: Hello there!
%}

{%
$_name = "there";$_text2 = "Hello " . $_name . "."; print ($_text2 );
# returns: Hello there.
%}

{%
$_name = "there";$_text3 = "Hello ";
$_text3 .=$_x3 . "!";

print ( $_text3 ); # returns: Hello there! %} {%$_text4 = "Hello, " . $CustomerName; print ($_text4 );
# returns: Hallo, Marcus Doe
# \$CustomerName contains the customer name after login.
%}``````

## Operator precedence

The operator precedence determines how an operator connects two expressions. Thus, the result of the expression 1 + 5 * 3 equals 16 and not 18 because the multiplication operator (*) precedes the addition operator (+). You can use brackets to influence operator precedence. Thus, (1 + 5) * 3 equals 18. If operators have equal priority, associativity from left to right is used.

The following table shows the operator’s precedence. The operators are listed in descending order. The operator with the highest precedence is at the top.

Associativity Operator

right

!

left

* / %

left

+ - .

no direction

< <= > >=

no direction

== =! === !==

left

&&

left

||

right

= += -= *= /= .= %=