Category: 10. PHP
-
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,…
-
Maths Functions
To enable mathematical operations, PHP has mathematical (arithmetic) operators and a number of mathematical functions. In this chapter, the following mathematical functions are explained with examples. PHP abs() Function The abs() function is an in-built function in PHP iterpreter. This function accepts any number as argument and returns a positive value, disregarding its sign. Absolute…
-
Files & I/O
This chapter will explain following functions related to files − Opening and Closing Files The PHP fopen() function is used to open a file. It requires two arguments stating first the file name and then mode in which to operate. Files modes can be specified as one of the six options in this table. Sr.No Mode &…
-
Integers
Integer is one of the built-in scalar types in PHP. A whole number, without a decimal point in the literal, is of the type “int” in PHP. An integer can be represented in decimal (base 10), hexadecimal (base 16), octal (base 8) or binary (base 2) notation. To use octal notation, a number is preceded…
-
Boolean
In PHP, “bool” is one of the built-in scalar data types. It is used to express the truth value, and it can be either True or False. A Boolean literal uses the PHP constants True or False. These constants are case-insensitive, in the sense, true, TRUE or True are synonymous. You can declare a variable…