Anonymous functions

Examples: Anonymous function example Anonymous functions, also known as closures, allow the creation of functions which have no specified name. They are most useful as the value of callback parameters, but they have many other uses. <?php echo preg_replace_callback('~-([a-z])~', function ($match) {     return strtoupper($match[1]); }, 'hello-world'); // outputs helloWorld ?> Anonymous function variable assignment example Closures can

Internal (built-in) functions

Variable functions

Examples: Variable function example PHP supports the concept of variable functions. This means that if a variable name has parentheses appended to it, PHP will look for a function with the same name as whatever the variable evaluates to, and will attempt to execute it. Among other things, this can be used to implement callbacks, function tables, and so forth. Variable functions won't work with language constructs such as echo, print, unset(), isset(), empty(), includ

Returning values

Examples: Use of return <?php function square($num) {     return $num * $num; } echo square(4);   // outputs '16'. ?> Returning an array to get multiple values A function can not return multiple values, but similar results can be obtained by returning an array. <?php function small_numbers() {     return array (0, 1, 2); } list ($zero, $one, $two) = small_numbers(); ?> Returning a reference from a function

Function arguments

Examples: Passing arrays to functions Information may be passed to functions via the argument list, which is a comma-delimited list of expressions. The arguments are evaluated from left to right. PHP supports passing arguments by value (the default), passing by reference, and default argument values. Variable-length argument lists are also supported. <?php function takes_array($input) {     echo "$input[0] + $input[1] = ", $input[0]+$input[1]; } ?>

User-defined functions

Examples: Pseudo code to demonstrate function uses A function may be defined using syntax such as the following: <?php function foo($arg_1, $arg_2, /* ..., */ $arg_n) {     echo "Example function.\n";     return $retval; } ?> Conditional functions Functions need not be defined before they are referenced, except when a function is conditionally defined as shown in the two examples below. When a function is defined in a conditional m

goto

(PHP 5 >= 5.3.0, PHP 7) Examples: goto example The goto operator can be used to jump to another section in the program. The target point is specified by a label followed by a colon, and the instruction is given as goto followed by the desired target label. This is not a full unrestricted goto. The target label must be within the same file and context, meaning that you cannot jump out of

include_once

(PHP 4, PHP 5, PHP 7) Examples: include_once with a case insensitive OS in PHP 4 With PHP 4, _once functionality differs with case-insensitive operating systems (like Windows) so for example: <?php include_once "a.php"; // this will include a.php include_once "A.php"; // this will include a.php again! (PHP 4 only) ?>

require_once

(PHP 4, PHP 5, PHP 7)

include

(PHP 4, PHP 5, PHP 7) Examples: Basic include example The include statement includes and evaluates the specified file. The documentation below also applies to require. Files are included based on the file path given or, if none is given, the include_path specified. If the file isn't found in the include_path, include will finally check in the calling script's own directory and the curr