PHP array_map() Function
Complete PHP Array Reference Manual
Example
Apply a function to every value in an array, multiply each value by itself, and return an array with the new values:
Run Example »
Definition and Usage
The array_map() function applies a user-defined function to every value of an array and returns an array with the values after the function has been applied.
**Tip:** You can pass one or more arrays to the function.
Syntax
array_map(
myfunction,array1,array2,array3
...)
| Parameters | Description |
|---|---|
| myfunction | Required. The name of a user-defined function, or null. |
| array1 | Required. Specifies the array. |
| array2 | Optional. Specifies an array. |
| array3 | Optional. Specifies an array. |
Technical Details
| Return Value: | Returns an array containing the values produced by the user-defined function applied to each element array1 of the array. |
|---|---|
| PHP Version: | 4.0.6+ |
More examples
Example 1
Use a user-defined function to change the values of an array:
Run Example »
Example 2
Using two arrays:
Run Example »
Example 3
Change all letters of the array values to uppercase:
" horse " , " Type " => " mammal " ) ; print_r ( array_map ( " myfunction " , $a ) ) ; ?>Run Example »
Example 4
When the function name is set to null:
Run Example »
Complete PHP Array Reference Manual