## If Statement

It is used to execute an instruction or block of instructions only if a condition is fulfilled.

Syntax: –

```if (condition)
{
block of statements;
}
```

## If statement with logical operator

```if ( (condition1) && (condition2) )
{
block of statements;
}

```

## If else Statement

if… else statement is used when a different sequence of instructions is to be executed depending
on the logical value(True/False) of the condition evaluated.

Syntax: –

```if(condition)
{
Statement_1_Block;
}
else
{
Statement_2_Block;
}
Statement_3;
```

## Else If Statement

To show a multi-way decision based on several conditions, we use else if statement.

Syntax: –

```If(condition_1)
{
statements_1_Block;
}
else if(condition_2)
{
statement_2_Blocks;
}
else if(condition_n)
{
Statements_n_Block;
}
else
statements_x;
```

## Switch Statement

Check several possible constant values for an expression.

Syntax: –

```switch(expression){
case expression 1:
block of statements 1;
break;
case expression2;:
block of statements 2;
break;
.
.
default:
default block of instructions;
}

```

All the cases will be evaluated if you don’t use a break statement.

```switch(expression){
case expression 1:
block of statements 1;
break;
case expression 2:
case expression 3:
block of statements 2;
break;
default:
default block of instructions;
}
```

## Tutorial for Spaceship operators

### What is Spaceship operators?

PHP 7 introduces a new spacecraft operator (=>) for comparing two words. It’s also known as the combined contrast operator.

The spacecraft operator yields 0 if the two operands are equal, 1 if the left is bigger, and -1 if the right is larger. In the following table, the three-way comparison is essentially shown:

Example:-

Output:-

## Tutorial for Array operators

### What is Array Operators?

The array operators are used to compare arrays. To compare various arrays, use the operations shown below. Make sure you’re using proper grammar.

• Operator Name Example Result
• `+` Union `\$x + \$y` Union of \$x and \$y
• `==` Equality `\$x == \$y `Returns true if `\$x `and` \$y `have the same key/value pairs
• `=== `Identity` \$x === \$y `Returns true if` \$x` and `\$y` have the same key/value pairs in the same order and of the same types
• `!= `Inequality `\$x != \$y` Returns true if `\$x` is not equal to `\$y`
• `<> `Inequality `\$x <> \$y `Returns true if `\$x` is not equal to` \$y`
• `!== `Non-identity `\$x !== \$y` Returns true if `\$x` is not identical to `\$y`

Example:-

Output:-

## Tutorial for String operators

### What is String operators?

There are two string operators available. The usage of numerical numbers might lead to unexpected outcomes:

1. The PHP operator (.) is also known as the concatenation operator. It joins separate threads together.
2. The PHP operator (.=) is also known as the combined assignment operator. It connects the argument to the one on the right page, on the left.
• Operator Name Example Result
• `. `Concatenation `\$txt1 . \$txt2 `Concatenation of `\$txt1` and `\$txt2`
• `.= `Concatenation assignment `\$txt1 .= \$txt2` Appends `\$txt2 `to `\$txt1`

Example:-

Output:-

## Tutorial for Logical operators

### What is Logical operators?

They combine conditionals and are mostly used to track several conditions at the same time. For example, the PHP (or) operator verifies that at least one out of every two is correct. If you want to check if they’re both legitimate, you may use the PHP (and) operator. For further information, see the table below:

• Operator Name Example Result
• and And `\$x` and `\$y `True if both `\$x` and `\$y` are true
• `or Or \$x` or `\$y` True if either `\$x` or `\$y` is true
• `xor Xor` `\$x xor \$y `True if either `\$x` or `\$y `is true, but not both
• && And `\$x && \$y` True if both `\$x` and `\$y` are true
• `|| Or` `\$x || \$y `True if either `\$x` or `\$y` is true
• !` Not !\$x `True if `\$x `is not true

Example:-

Output:-

## Tutorial for Increment/Decrement operators

### What is Increment/Decrement operators?

These operations raise (increase) or reduce (decrease) the value of a vector (decrease). Because just one operator is employed, they are frequently referred to as uniform operators. To raise or reduce a value by a factor of one, operators for increasing and decreasing are used. Pre-incrementing operator The new \$x value is returned when the value is added to it. See the table below for a better understanding:

• Operator Name Description
• `++\$x` Pre-increment Increments `\$x` by one, then returns `\$x`
• `\$x++ `Post-increment Returns `\$x,` then increments `\$x` by one
• `--\$x `Pre-decrement Decrements `\$x` by one, then returns `\$x`
• `\$x--` Post-decrement Returns `\$x`, then decrements `\$x` by one

Example:-

Output:-

## Tutorial for Comparison operators

### What is Comparison operators?

The comparison operator denotes the connection between two or more values in a number or a series. These php operators are simply used to compare the two values’ integers or strings. We’ll show you how to compare them using php operators in this article. This PHP operator is necessary for looking for discrepancies or correlations between values and variables. It behaves like a boolean, yielding either True or False. For example, if the two variables you’re comparing don’t have the same value, the PHP not equal to operator will return true.

• Operator Name Example Result
• `== `Equal` \$x == \$y` Returns true if \$x is equal to `\$y`
• `=== `Identical `\$x === \$y` Returns true if \$x is equal to \$y, and they are of the same type
• `!= `Not equal `\$x != \$y` Returns true if `\$x` is not equal to `\$y`
• `<> `Not equal `\$x <> \$y` Returns true if `\$x` is not equal to `\$y`
• `!== `Not identical `\$x !==` `\$y` Returns true if `\$x` is not equal to `\$y`, or they are not of the same type
• `>` Greater than `\$x > \$y` Returns true if `\$x` is greater than `\$y`
• `<` Less than \$x `< \$y `Returns true if `\$x` is less than `\$y`
• `>= `Greater than or equal to `\$x >= \$y` Returns true if `\$x` is greater than or equal to `\$y`
• `<=` Less than or equal to `\$x <= \$y` Returns true if `\$x` is less than or equal to `\$y`

Example:-

Outputs:-

## Tutorial for Assignment operators

### What is Assignment operators?

PHP Assignment operators are used to assign values to variables. The right side value is substituted for the left side value in the operand variable. Operators in this category are in charge of assigning variables. The most frequent assignment operator is =, which assigns the operand’s right side to the left variable.

• Assignment Same as… Description
• `x = y x = y` The left operand gets set to the value of the expression on the right
• `x += y x = x + y` Addition
• `x -= y x = x - y` Subtraction
• `x *= y x = x * y `Multiplication
• `x /= y x = x / y` Division
• `x %= y x = x % y` Modulus

Example:-

Output:-

## Tutorial for Arithmetic operators

### What is Arithmetic operators?

The arithmetic operator is used to do simple arithmetic operations such as adding, subtracting, multiplying, and so on. Simple arithmetic behavior of numerical values may be implemented using these operators. The table below demonstrates how the findings are used and what outcomes are achieved.

• Operator Name Example Result
• `+` Addition `\$x + \$y` Sum of `\$x` and `\$y`
• `- `Subtraction `\$x - \$y` Difference of `\$x` and` \$y`
• `*` Multiplication` \$x * \$y` Product of `\$x `and `\$y`
• `/ `Division` \$x / \$y` Quotient of `\$x` and `\$y`
• `% `Modulus `\$x % \$y` Remainder of `\$x` divided by `\$y`
• `** `Exponentiation `\$x ** \$y` Result of raising \$x to the `\$y'th` power (Introduced in PHP 5.6)

Example:-

Output:-

## What is Operators in PHP?

Operators are symbols that tell the PHP processor what actions should be taken. The Add (+) sign, for example, instructs PHP to combine two variables or values, but the bigger (>) symbol instructs PHP to compare two values. Don’t make the mistake of assuming that operators and functions are the same. Instead of functional, such operators might be used (such as the PHP ternary).

• Arithmetic operators
• Assignment operators
• Comparison operators
• Increment/Decrement operators
• Logical operators
• String operators
• Array operators
• Spaceship operators