Definition and usage
The Array_map () function returns an array after the user-defined function is functional. The number of arguments that the callback function accepts should be the same as the number of arrays passed to the Array_map () function.
Grammar
Array_map (Function,array1,array2,array3 ...)
| Parameters |
Describe |
| function |
Necessary. The name of the user-defined function, or null. |
| Array1 |
Necessary. Specifies the array. |
| Array2 |
Optional. Specifies the array. |
| Array3 |
Optional. Specifies the array. |
Example 2
Use multiple parameters:
<?phpfunction MyFunction ($v 1, $v 2) { if ($v 1=== $v 2) { return "Same"; } return "Different";} $a 1 = Array ("Horse", "Dog", "Cat"), $a 2 = Array ("Cow", "Dog", "Rat");p Rint_r (Array_map ("MyFunction", $a 1, $a 2)); >
Output:
Array ([0] = different [1] = same [2] = different)
Example 3
See what happens when a custom function name is set to null:
<?php$a1 = Array ("Dog", "Cat"), $a 2 = Array ("Puppy", "Kitten");p Rint_r (Array_map (null, $a 1, $a 2)); >
Output:
Array ([0] = = Array ([0] = Dog [1] = Puppy) [1] = = Array ([0] = = Cat [1] = Kitten))
PHP Array_map ()