


Arraylist sorting php array_map array function usage instructions
Jul 29, 2016 am 08:46 AMCopy 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:
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.

Hot Article

Hot tools Tags

Hot Article

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

11 Best PHP URL Shortener Scripts (Free and Premium)

Working with Flash Session Data in Laravel

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

Simplified HTTP Response Mocking in Laravel Tests

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

12 Best PHP Chat Scripts on CodeCanyon

Announcement of 2025 PHP Situation Survey
