Home >Backend Development >PHP Tutorial >php-Arrays function-array_map-applies the callback function to the cells of the given array_PHP tutorial

php-Arrays function-array_map-applies the callback function to the cells of the given array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:51:171303browse

array_map() applies the callback function to the given array unit

【Function】
This function will return an array,
This array contains all units in array1 after callback has been applied to them.
The number of parameters received by the callback function should be consistent with the number of arrays passed to the array_map() function.
【Scope of use】
​​​​​ php4>4.0.6, php5.
【Use】
array array_map( callback callback,array arr1[,array...] )
​​​​ callback/required/a relatively standard callback function provided for users
          arr1/required/array for comparison
          array.../optional/array for comparison
【Example】
[php]
//Define callback function
function cube($n){
         return ($n*$n*$n);
}
$a=array(1,2,3,4,5);
$b=array_map("cube",$a);
var_dump($b);
/*
array(5) {
[0]=>
int(1)
[1]=>
int(8)
[2]=>
int(27)
[3]=>
int(64)
[4]=>
int(125)
}
*/


Excerpted from zuodefeng’s notes

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/478214.htmlTechArticlearray_map() applies the callback function to the given array unit [Function] This function will return an array, This array contains all the cells in array1 that have been affected by callback...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn