- BASICS
- Quotes
- Constants
- Control Structures
- Reference
- Number Systems
- VARIABLES
- Definition
- Variable Variable
- Exists
- Type Casting
- OPERATORS
- Aritmetic
- Bitwise
- String
- Comparison
- Logical
- FUNCTION
- Definition
-
Anonymous
- Reference
- Variable Arguments
- ARRAY
- Basics
- Operations
- Create
- Search
- Modify
- Sort
- Storage
- STRING
- String Basics
- String Compare
- String Search
- String Replace
- String Format
- String Regexp
- String Parse
- Formating
- Json
- STREAMS
- File Open
- Read File
- Read Csv
- File Contents
- Context
- Ob_start
- OOP
- Object Instantiation
- Class Constructor
- Interfaces, Abstract
- Resource Visibility
- Class Constants
- Namespaces
- HTTP
- Headers
- File Uploads
- Cookies
- Sessions
Declaration
Be aware of the ; after function declaration (parse error syntax, without it).
/**
* Anonimous function - declaration
*/
$a = function($var) {
return "Hello $var";
}; // ; at the end
echo $a('World'); // outputs: Hello World
Callbacks
Anonymous functions are useful when using callback functions.
/**
* Callbaks with filter and map
*/
$A = array(0, 3, 10);
$B = array_filter(
$A, fn($x) => $x % 2 == 0 // is even
);
$C = array_map(
fn($x) => $x*$x, $A // square
);
print_r($B); // 0, 100
print_r($C); // 0, 9, 100
Last update: 531 days ago