Categories
PHP

Array Internal Pointers

Along with the keys and the associated values stored in an array, PHP maintains an internal index that points to the current element in the array.

Categories
PHP

Array Iteration

The easiest way to iterate through each element of an array is with foreach. The foreach statement lets you run a code block once for each element in an array.

Categories
PHP

Creating Arrays

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.

Categories
PHP

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.

Categories
PHP

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.

Categories
PHP

Ternary, Elvis, and Null Coalescing Operators

In this tutorial, you’ll learn the usage of Ternary operator, ?: Elvis operator, ?? Null coalescing operator, and ??= Null coalescing assignment operator.

Categories
PHP

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.

Categories
PHP

If elseif else and Switch Case Conditional Statements

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.

Categories
PHP

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.

Categories
PHP

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.