An array is an ordered set of variables, in which each variable is called an element. There are two types of arrays: numbered and associative. The first type of array uses numerical keys, whereas the latter type can also use strings as keys.
Author: BrainBell
Using GOTO Operator
In this tutorial, you’ll create a goto operator loop. The goto operator performs a jump to a specified label (line) within the same file.
While, For, Foreach Loops
Loops add control to scripts so that statements can be repeatedly executed as long as a conditional expression remains true. There are four loop statements in PHP: while, do…while, for, and foreach. The first three are general-purpose loop constructs, and foreach is used exclusively with arrays.
In this tutorial, you’ll learn the usage of Ternary operator, ?: Elvis operator, ?? Null coalescing operator, and ??= Null coalescing assignment operator.
Conditional Expressions
Comparison operators let you compare two expressions. If the comparison test is successful, the expression evaluates to true, and if the test fails, the expression evaluates to false. You often use comparison operators with conditional statements (e.g. if…else ) and loops (e.g. while loop, for loop, etc.). The logical operators work on Boolean values. You often use logical operators to combine the results of two (or more) of the comparison operators.
The control structures in PHP are similar in syntax to those in other high-level programming languages. Conditionals add control to scripts and permit branching so that different statements are executed depending on whether expressions are true or false. In this tutorial you’ll learn the two branching statements: if, with the optional else clause, and switch with two or more case clauses.
Testing, setting, and unsetting variables
Before attempting to use variables that come from an external source such as a user-submitted form, you must check whether those variables are defined or not. isset() function is one of the most common tests to check whether a variable has been defined.
Strict Typing Mode
In PHP the declare(strict_types = 1); directive enables strict mode. In strict mode, only a variable of the exact type of the “type declaration” will be accepted, or a TypeError will be thrown.
Type Declaration
A loosely typed language doesn’t offer the best performance since its compiler has more work to do when trying to determine the data types of its variables. On the other hand, the strict type languages consume less memory and give better performance at runtime than loosely typed languages. Since version 7, PHP offers the possibility of strict type function arguments, return values, and class properties (PHP 7.4), known as “Type declarations”.
A constant is a variable with a value that cannot be changed by the script. Therefore, such a value must be assigned at the same time that the constant is created. Constants may not be redefined or undefined once they have been set.