Author: Awais Farooq
-
Spread Operator
PHP recognizes the three dots symbol (…) as the spread operator. The spread operator is also sometimes called the splat operator. This operator was first introduced in PHP version 7.4. It can be effectively used in many cases such as unpacking arrays. Example 1 In the example below, the elements in $arr1 are inserted in $arr2 after…
-
Conditional Operators Examples
You would use conditional operators in PHP when there is a need to set a value depending on conditions. It is also known as ternary operator. It first evaluates an expression for a true or false value and then executes one of the two given statements depending upon the result of the evaluation. Ternary operators offer…
-
Array Operators
PHP defines the following set of symbols to be used as operators on array data types − Symbol Example Name Result + $a + $b Union Union of $a and $b. == $a == $b Equality TRUE if $a and $b have the same key/value pairs. === $a === $b Identity TRUE if $a and…
-
String Operators
There are two operators in PHP for working with string data types: concatenation operator (“.”) and the concatenation assignment operator (“.=”). Read this chapter to learn how these operators work in PHP. Concatenation Operator in PHP The dot operator (“.”) is PHP’s concatenation operator. It joins two string operands (characters of right hand string appended…
-
Assignment Operators Examples
You can use assignment operators in PHP to assign values to variables. Assignment operators are shorthand notations to perform arithmetic or other operations while assigning a value to a variable. For instance, the “=” operator assigns the value on the right-hand side to the variable on the left-hand side. Additionally, there are compound assignment operators…
-
Logical Operators Examples
In PHP, logical operators are used to combine conditional statements. These operators allow you to create more complex conditions by combining multiple conditions together. Logical operators are generally used in conditional statements such as if, while, and for loops to control the flow of program execution based on specific conditions. The following table highligts the logical operators that…
-
Comparison Operators Examples
In PHP, Comparison operators are used to compare two values and determine their relationship. These operators return a Boolean value, either True or False, based on the result of the comparison. The following table highligts the comparison operators that are supported by PHP. Assume variable $a holds 10 and variable $b holds 20, then −…
-
Arithmetic Operators Examples
In PHP, arithmetic operators are used to perform mathematical operations on numeric values. The following table highligts the arithmetic operators that are supported by PHP. Assume variable “$a” holds 42 and variable “$b” holds 20 − Operator Description Example + Adds two operands $a + $b = 62 – Subtracts the second operand from the…
-
Operators Types
What are Operators in PHP? As in any programming language, PHP also has operators which are symbols (sometimes keywords) that are predefined to perform certain commonly required operations on one or more operands. For example, using the expression “4 + 5” is equal to 9. Here “4” and “5” are called operands and “+” is called an operator. We…
-
Return Type Declarations
PHP version 7 extends the scalar type declaration feature to the return value of a function also. As per this new provision, the return type declaration specifies the type of value that a function should return. We can declare the following types for return types − To implement the return type declaration, a function is…