Category: 12. PHP
-
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…
-
Scalar Type Declarations
The feature of providing type hints has been in PHP since version 5. Type hinting refers to the practice of providing the data type of a parameter in the function definition. Before PHP 7, it was possible to use only the array, callable, and class for type hints in a function. PHP 7 onwards, you can also…
-
Date & Time
The built-in library of PHP has a wide range of functions that helps in programmatically handling and manipulating date and time information. Date and Time objects in PHP can be created by passing in a string presentation of date/time information, or from the current system’s time. PHP provides the DateTime class that defines a number…
-
File Include
The include statement in PHP is similar to the import statement in Java or Python, and #include directive in C/C++. However, there is a slight difference in the way the include statement works in PHP. The Java/Python import or #include in C/C++ only loads one or more language constructs such as the functions or classes defined in one file into the…
-
Compound Types
Data types in PHP can be of “scalar type” or “compound type”. Integer, float, Boolean and string types are scalar types, whereas array and object types are classified as compound types. Values of more than one types can be stored together in a single variable of a compound type. In PHP, objects and arrays are…
-
Heredoc & Nowdoc
PHP provides two alternatives for declaring single or double quoted strings in the form of heredoc and newdoc syntax. Heredoc Strings in PHP The heredoc strings in PHP are much like double-quoted strings, without the double-quotes. It means that they don’t need to escape quotes and expand variables. Heredoc Syntax First, start with the “<<<” operator. After this operator,…