Category: Functions

  • Global Variables

    In PHP, any variable that can be accessed from anywhere in a PHP script is called as a global variable. If the variable is declared outside all the functions or classes in the script, it becomes a global variable. While global variables can be accessed directly outside a function, they aren’t automatically available inside a function.…

  • Local Variables

    Scope can be defined as the range of availability a variable has to the program in which it is declared. PHP variables can be one of four scope types − Local Variables A variable declared in a function is considered local; that is, it can be referenced solely in that function. Any assignment outside of…

  • Variable Functions

    PHP Variable Handling Functions are the inbuilt PHP library functions that enable us to manipulate and test php variables in various ways. Installation There is no installation needed to use PHP variable functions; they are part of the PHP core and comes along with standard PHP installation. Runtime Configuration This extension has no configuration directives defined…

  • Arrow Functions

    Arrow functions were added in PHP 7.4 to make it easier and faster to write anonymous functions. Instead of the regular “function” term, you can now type “fn”. The new version simplifies your code, making it cleaner and more readable. Arrow functions are perfect for short, one-line functions because they automatically return the result without the need for an…

  • Anonymous Functions

    What are Anonymous Functions? PHP allows defining anonymous functions. Normally, when we define a function in PHP, we usually provide it a name which is used to call the function whenever required. In contrast, an anonymous function is a function that doesnt have any name specified at the time of definition. Such a function is also called closure or lambda…

  • Strict Typing

    PHP is widely regarded as a weakly typed language. In PHP, you need not declare the type of a variable before assigning it any value. The PHP parser tries to cast the variables into compatible type as far as possible. For example, if one of the values passed is a string representation of a number,…

  • Variable Scope

    In PHP, the scope of a variable is the context within which it is defined and accessible to the extent in which it is accessible. Generally, a simple sequential PHP script that doesnt have any loop or a function etc., has a single scope. Any variable declared inside the “<?php” and “?>” tag is available…

  • Type Hints

    PHP supports using “type hints” at the time of declaring variables in the function definition and properties or instance variables in a class. PHP is widely regarded as a weakly typed language. In PHP, you need not declare the type of a variable before assigning it any value. The PHP parser tries to cast the…

  • Recursive Functions

    A recursive function is such a function that calls itself until a certain condition is satisfied. In PHP, it is possible to defines a recursive function. Calculation of Factorial using Recursion The most popular example of recursion is calculation of factorial. Mathematically factorial is defined as − n!=n(n-1)! It can be seen that we use…

  • Passing Functions

    To a function in PHP, in addition to scalar types, arrays, and objects, you can also pass a function as one of its arguments. If a function is defined to accept another function as an argument, the passed function will be invoked inside it. PHPs standard library has certain built-in functions of this type, where…