Author: saqibkhan
-
Named Arguments
The feature of Named Arguments has been introduced in PHP with the version 8.0. It is an extension of the existing mechanism of passing positional arguments to a function while calling. By default, values of passed arguments are copied to the corresponding formal arguments at the same position. This feature of named arguments in PHP…
-
Default Arguments
Like most of the languages that support imperative programming, a function in PHP may have one or more arguments that have a default value. As a result, such a function may be called without passing any value to it. If there is no value meant to be passed, the function will take its default value…
-
Call by Reference
PHP uses the “call by value” mechanism, by default, for passing arguments to a function. If the arguments within the function are changed, the changes do not reflect outside of the function. To allow a function to modify its arguments, the “call by reference” mechanism must be used. In PHP, a reference variable acts as…
-
Call by Value
By default, PHP uses the “call by value” mechanism for passing arguments to a function. When a function is called, the values of actual arguments are copied to the formal arguments of the function’s definition. During the execution of the function body, if there is any change in the value of any of the formal arguments,…
-
Function Parameters
A function in PHP may be defined to accept one or more parameters. Function parameters are a comma-separated list of expressions inside the parenthesis in front of the function name while defining a function. A parameter may be of any scalar type (number, string or Boolean), an array, an object, or even another function. The…
-
Functions
Like most of the programming languages, a function in PHP is a block of organized, reusable code that is used to perform a single, related action. Functions provide better modularity for your application and a high degree of code reuse. PHP supports a structured programming approach by arranging the processing logic by defining blocks of…
-
Constant Arrays
It was not possible to declare a constant array before PHP version 5.6. From PHP 5.6 onwards, you can use the “const” keyword to declare a constant array. From PHP 7 onwards, constant arrays can also be formed with define() function. A constant array is an array which cannot be modified after it has been…
-
Multidimensional Array
A multidimensional array is an array of arrays. In a PHP array, each element can be another array. If the array consists of values or key-value pairs with values being of singular scalar types, it is a one-dimensional array. If each element in an array is an array of one or more scalar values, it…
-
Associative Array
If each element in a PHP array is a key-value pair, such an array is called an associative array. In this type of array, each value is identified by its associated key and not an index. How to Declare an Associative Array in PHP? Both the approaches of declaring an array – the array() function and…
-
Indexed Array
In PHP, the array elements may be a collection of key-value pairs or it may contain values only. If the array consists of values only, it is said to be an indexed array, as each element is identified by an incrementing index, starting with “0”. An indexed array in PHP may be created either by…