PHP array function array_map () notes. PHP array function array_map () note definition and usage the array_map () function returns the array after the user-defined function acts. The number of parameters accepted by the callback function should be the same as the number of parameters passed to the array_map () function of the PHP array function array_map ().
Definition and usage
The array_map () function returns the array after the user-defined function is applied. The number of parameters accepted by the callback function should be the same as the number of arrays passed to the array_map () function.
Syntax
Array_map (function, array1, array2, array3 ...)
Parameters |
Description |
Function |
Required. The name of the user-defined function, or null. |
Array1 |
Required. Specified array. |
Array2 |
Optional. Specified array. |
Array3 |
Optional. Specified array. |
Example 1
Output:
Array ([0] => Horse [1] => Fido [2] => Cat)
Example 2
Use multiple parameters:
Output:
Array ([0] => different [1] => same [2] => different)
Example 3
See when the custom function name is set to null:
Output:
Array (
[0] => Array ([0] => Dog [1] => Puppy)
[1] => Array ([0] => Cat [1] => Kitten)
)
Articles you may be interested in
- PHP array function array_walk () notes
- PHP generates continuous numbers (letters) array function range () analysis, PHP lottery program function
- Php pushes an element to the array header (array_unshift usage)
- Use php functions in the smarty template and how to use multiple functions for a variable in the smarty Template
- Php uses the filter function to verify the mailbox, url, and IP address
- PHP merges arrays + and array_merge
- Introduction to array union, intersection, and difference set functions in php
- Php searches for the existence of a value in the array (in_array (), array_search (), array_key_exists ())
The array_map () function returns the array after the user-defined function is used. The number of parameters accepted by the callback function should be passed to the array_map () function...