Category: 12. PHP

  •  Switch Statement

    The switch statement in PHP can be treated as an alternative to a series of if…else statements on the same expression. Suppose you need to compare an expression or a variable with many different values and execute a different piece of code depending on which value it equals to. In such a case, you would use multiple if…elseif…else constructs.…

  • If…Else Statement

    The ability to implement conditional logic is the fundamental requirement of any programming language (PHP included). PHP has three keywords (also called as language constructs) – if, elseif and else – are used to take decision based on the different conditions. The if keyword is the basic construct for the conditional execution of code fragments. More often than not, the if keyword is…

  • Decision Making

    A computer program by default follows a simple input-process-output path sequentially. This sequential flow can be altered with the decision control statements offered by all the computer programming languages including PHP. Decision Making in a Computer Program Decision-making is the anticipation of conditions occurring during the execution of a program and specified actions taken according…

  • Spaceship Operator

    The Spaceship operator is one of the many new features introduced in PHP with its 7.0 version. It is a three-way comparison operator. The conventional comparison operators (<, >, !=, ==, etc.) return true or false (equivalent to 1 or 0). On the other hand, the spaceship operator has three possible return values: -1,0,or 1.…

  • Null Coalescing Operator

    The Null Coalescing operator is one of the many new features introduced in PHP 7. The word “coalescing” means uniting many things into one. This operator is used to replace the ternary operation in conjunction with the isset() function. Ternary Operator in PHP PHP has a ternary operator represented by the “?” symbol. The ternary operator compares…

  • 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…