Home Backend Development PHP Tutorial Arraylist sorting php array_map array function usage instructions

Arraylist sorting php array_map array function usage instructions

Jul 29, 2016 am 08:46 AM

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 "<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>";
/ /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: <br>";
echo "<pre>";
print_r($results);
echo "</pre>";


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.

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 Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

11 Best PHP URL Shortener Scripts (Free and Premium) 11 Best PHP URL Shortener Scripts (Free and Premium) Mar 03, 2025 am 10:49 AM

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel Working with Flash Session Data in Laravel Mar 12, 2025 pm 05:08 PM

Working with Flash Session Data in Laravel

Build a React App With a Laravel Back End: Part 2, React Build a React App With a Laravel Back End: Part 2, React Mar 04, 2025 am 09:33 AM

Build a React App With a Laravel Back End: Part 2, React

Simplified HTTP Response Mocking in Laravel Tests Simplified HTTP Response Mocking in Laravel Tests Mar 12, 2025 pm 05:09 PM

Simplified HTTP Response Mocking in Laravel Tests

cURL in PHP: How to Use the PHP cURL Extension in REST APIs cURL in PHP: How to Use the PHP cURL Extension in REST APIs Mar 14, 2025 am 11:42 AM

cURL in PHP: How to Use the PHP cURL Extension in REST APIs

12 Best PHP Chat Scripts on CodeCanyon 12 Best PHP Chat Scripts on CodeCanyon Mar 13, 2025 pm 12:08 PM

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey Announcement of 2025 PHP Situation Survey Mar 03, 2025 pm 04:20 PM

Announcement of 2025 PHP Situation Survey

Notifications in Laravel Notifications in Laravel Mar 04, 2025 am 09:22 AM

Notifications in Laravel

See all articles