- 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
Map, Walk
Apply a user function to every member of an array.
/**
* array_map, array_walk()
*
* Array walk needs reference
*/
function cube($n)
{
return pow($n, 3);
}
$A = [1, 2, 3];
$B = [1, 2, 3];
$C = [1, 2, 3];
$D = [1, 2, 3];
$A = array_map('cube', $A);
$B = array_map(fn($x) => pow($x, 3), $B);
array_walk($C, fn(&$x) => $x = pow($x, 3));
array_walk($D, fn(&$x) => $x *= 2); // Look Here
print_r($A); // 1 8 27
print_r($B); // 1 8 27
print_r($C); // 1 8 27
print_r($D); // 2 4 6
Questions and answers
Check if an array key exists
- a) array_key_exists('a', $arr)
- b) isset($arr['a'])
Advance the pointer of an array
- a) next()
- b) key()
- c) current()
One of this needs reference
- a) array_walk
- b) array_map