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

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.

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.

Categories
PHP

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”.

Categories
PHP

Constants

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.

Categories
PHP

Type Conversion: Convert variable data type

PHP provides several mechanisms to allow variables of one type to be considered as another type. Variables can be explicitly converted to another type with the settype, strval, intval, boolval and floatval functions.