Home >> PHP >> array_map() function in PHP

array_map() function in PHP

The array_map() function sends each value of an array to a user defined function and gets an array with new values applied by the user defined function.

Syntax

array_map(myfunction, array1, array2, ...)

Example

function square($x){
    return($x * $x);
}
$array = array(2,3,4,5,6,7);
print_r(array_map("square",$array));

Output

Array ( [0] => 4 [1] => 9 [2] => 16 [3] => 25 [4] => 36 [5] => 49 )

Post Your Comment

Next Questions
array_merge() function
array_merge_recursive() function
array_multisort() function
array_pad() function
array_pop() function
array_product() function
array_push() function
array_rand() function
array_reduce() function
array_reverse() function
array_search() function
array_shift() function
array_slice() function
array_splice() function
array_sum() function
array_udiff() function
array_udiff_assoc() function
array_udiff_uassoc() function
array_uintersect() function
array_uintersect_assoc() function
array_uintersect_uassoc() function
array_unique() function
array_unshift() function
array_values() function
array_walk() function

Copyright ©2022 coderraj.com. All Rights Reserved.