Home
Backend Development
PHP Tutorial
php array_map() array function usage instructions_PHP tutorial



php array_map() array function usage instructions_PHP tutorial
Jul 21, 2016 pm 03:27 PM
array
map
php
code
Instructions for use
function
callback
copy
Will
array
Copy code The code is as follows:
/*Function array_map() function: multi-array callback function---apply the callback function to
* 1. Syntax: array array_map (callback callback, array arr1 [, array ...])
* 2. Description: Returns an array that contains all the cells in arr1
* unit after 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 the 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
* when applied to Define the key name of the 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 numbers will be assigned uniformly. Index as key name
*/
//Example of using a single array
$websites=array("g"=>"google","b"=>"baidu","y" =>"yahoo");
//Output the original array
echo "<pre>";
print_r($websites);
echo "</pre>";
//Define a callback function for processing a single array
function change_value($value){
return ucfirst($value).".com";
}
$urls=array_map('change_value ',$websites);
echo "<pre>";
print_r($urls);
echo "</pre>";
//Example of using multiple arrays
$arr1=array(1,3,5,7);
$arr2=array(2,4,6,8);
//Define a callback function for processing multiple arrays
function func1($a,$b){
return $a*$b;
}
$results=array_map('func1',$arr1,$arr2);
echo "Use callback After the function processes multiple arrays, the result returned: <br>";
echo "<pre>";
print_r($results);
echo "</pre>";
The operation effect is as follows:
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

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?
3 weeks ago
By 王林
Two Point Museum: All Exhibits And Where To Find Them
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot tools Tags

Hot Article
How Long Does It Take To Beat Split Fiction?
3 weeks ago
By DDD
Repo: How To Revive Teammates
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Difficulty in updating caching of official account web pages: How to avoid the old cache affecting the user experience after version update?
3 weeks ago
By 王林
Two Point Museum: All Exhibits And Where To Find Them
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian

How To Set Up Visual Studio Code (VS Code) for PHP Development
