PHP - Function array_map()



Syntax

array array_map ( callback $callback, array $array1 [, array $array2...] );

Definition and Usage

It returns an array containing all the elements of array1 after applying the callback function to each one.

Parameters

Sr.No Parameter & Description
1

callback(Required)

The name of the user-made function, or null.

2

array1(Required)

It specifies an array.

3

array2(Optional)

It specifies an array.

4

array3(Optional)

It specifies an array.

Return Values

It returns an array containing all the processed elements of array1.

Example

Try out following example −

 

This will produce the following result −

Array ( [0] => 1 [1] => 8 [2] => 27 [3] => 64 [4] => 125 )

Using multiple arrays.


This will produce the following result −

Array ( [0] => different [1] => equal [2] => different [3] => equal )
php_function_reference.htm
Advertisements