Php-Arrays function-array_map-apply the callback function to the unit of the given array _ PHP Tutorial

Source: Internet
Author: User
Php-Arrays function-array_map-applies the callback function to the unit of the given array. Array_map () calls the callback function to a given array unit. [function] This function returns an array that contains all the units in array1. after callback, the callback function acts as array_map () calls the callback function to a given array unit.

[Function]
This function returns an array,
This array contains all units in array1 that have passed the callback function.
The number of parameters received by the callback function should be the same as the number of arrays passed to the array_map () function.
Scope of use]
Php4> 4.0.6, php5.
[Use]
Array array_map (callback, array arr1 [, array...])
Callback/required/provided by the user as a standard callback function
Arr1/required/comparative array
Array.../optional/array for comparison
[Example]
[Php]
// Define the callback function
Function cube ($ n ){
Return ($ n * $ n );
}
$ A = array (1, 2, 3, 4, 5 );
$ B = array_map ("cube", $ );
Var_dump ($ B );
/*
Array (5 ){
[0] =>
Int (1)
[1] =>
Int (8)
[2] =>
Int (27)
[3] =>
Int (64)
[4] =>
Int (125)
}
*/


Taken from zuodefeng's note

Http://www.bkjia.com/PHPjc/478214.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/478214.htmlTechArticlearray_map () calls the callback function to a given array unit [function] This function returns an array that contains all units in array1 that have passed through callback...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.