Arraylist sorting php array_map array function usage instructions

WBOY
Release: 2016-07-29 08:46:03
Original
1407 people have browsed it

Copy code The code is as follows:


/*Function array_map() function: multiple array callback function---apply the callback function to the units of the given array
* 1. Syntax: array array_map (callback callback , array arr1 [, array ...] )
* 2. Description: Returns an array that contains the
* units of all units in arr1 after the callback has been applied. The number of arguments accepted by callback should match the number of arrays passed to the array_map() function.
* 3. Notes:
* 3.1. When a multi-array callback function acts on an array, the key name of the original array will be retained, that is, the key name of the returned array is
* the key name applied to the given array
* 3.2. When the multi-array return function operates on two or more arrays, their lengths must be consistent, and the
* key names of the original multiple arrays will be ignored, and the numeric index will be uniformly assigned as the key name
*/
// Example of using a single array
$websites=array("g"=>"google","b"=>"baidu","y"=>"yahoo");
//Output the original array
echo "

"; <br>print_r($websites); <br>echo "
";
//Define a callback function for processing a single array
function change_value($value){
return ucfirst($value) .".com";
}
$urls=array_map('change_value',$websites);
echo "
"; <br>print_r($urls); <br>echo "
";
/ /Examples of using multiple arrays
$arr1=array(1,3,5,7);
$arr2=array(2,4,6,8);
//Define callback functions for processing multiple arrays
function func1($a,$b){
return $a*$b;
}
$results=array_map('func1',$arr1,$arr2);
echo "After using the callback function to process multiple arrays, Returned results:
";
echo "
"; <br>print_r($results); <br>echo "
";


The operation effect is as follows:

 php array_map数组函数使用说明

The above introduces the instructions for using arraylist sorting php array_map array function, including the content of arraylist sorting. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!