Php array_map function instance

Source: Internet
Author: User

Array_map
("= 4.0.6, PHP 5" in PHP 4)

Array_map-array of considerations for various elements of callback

Description
Array array_map (callback $ callback, array $ arr1 [, array $...])
Array_map () returns all content contained in an array. The callback function after arr1 is applied to each object. The number of parameters for callback function acceptance should comply with several arrays passed to array_map ()

Parameters

Callback
Each array in each element of the callback function.

Arr1
A series of runtime callback functions.

Array
The variable parameter list array runs through the callback function.


Return value
Returns all the contents in an array. The callback function after arr1 is applied to each object.

Modify

Version description
5.3.0 now you can use the lambda function as the callback.


Instance

Example #1 array_map ()

<? Php
Function cube ($ n)
{
Return ($ n * $ n );
}

$ A = array (1, 2, 3, 4, 5 );
$ B = array_map ("cube", $ );
Print_r ($ B );
?>
This makes $ B have:

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

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.