Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

what is array_map in php

array_map():
Send each element of an array to a user defined function, return an array as 
it or if required value can be process and return back new value given by the 
user defined function:

<?php

function funTable($el){
    return $el*2;
}
	
$arrMap = array(1,2,3,4,5,6,7,8,9,10);
$table = array_map('funTable',$arrMap);
print_r($table);
?>
Output:

Array
(
    [0] => 2
    [1] => 4
    [2] => 6
    [3] => 8
    [4] => 10
    [5] => 12
    [6] => 14
    [7] => 16
    [8] => 18
    [9] => 20
)
Source by onecompiler.com #
 
PREVIOUS NEXT
Tagged: #php
ADD COMMENT
Topic
Name
2+8 =