The PHP Array function array

Source: Internet
Author: User
Tags array functions return

Definitions and usage

The Array_map () function returns an array of the actions of the user's custom function. The number of arguments accepted by the callback function should be the same as the number of arrays passed to the Array_map () function.

Grammar

Array_map (Function,array1,array2,array3 ...)

Parameters Description
function Necessary. The name of the user's custom function, or null.
Array1 Necessary. The specified array.
Array2 Optional. The specified array.
Array3 Optional. The specified array.

Example 1

<?php
function MyFunction ($v) {
	if ($v = = "Dog") {return
		"Fido";
	}
	return $v;
}

$a = Array ("Horse", "Dog", "Cat");
Print_r (Array_map ("MyFunction", $a));
? >

Output:

Array ([0] => horse [1] => Fido [2] => Cat)

Example 2

Use multiple parameters:

<?php
function MyFunction ($v 1, $v 2) {
	if ($v 1 = = $v 2) {return
		"Same";
	}
	return "different";
}

$a 1 = array ("Horse", "Dog", "Cat");
$a 2 = Array ("Cow", "Dog", "Rat");
Print_r (Array_map ("MyFunction", $a 1, $a 2));
>

Output:

Array ([0] => different [1] => same [2] => different)

Example 3

See what happens when a custom function name is set to null:

<?php
$a 1 = array ("Dog", "Cat");
$a 2 = Array ("Puppy", "Kitten");
Print_r (Array_map (null, $a 1, $a 2));
? >

Output:

Array (
[0] => Array ([0] => Dog [1] => Puppy)
[1] => Array ([0] => Cat [1] => kitten)
)

Articles that you may be interested in

    • PHP Array function array_walk () notes
    • PHP generates a continuous number (letter) Array function range () analysis, PHP lottery program function
    • PHP presses the element to the array header (Array_unshift usage)
    • Use PHP functions in Smarty Templates and how to use multiple functions for a variable in smarty templates
    • The difference between the PHP merge array + and the Array_merge
    • Two-dimensional array removal of duplicate values and Array_unique functions
    • Summary of PHP array functions
    • How do I remove an element from a PHP array (unset,array_splice)?


Large-Scale Price Reduction
  • 59% Max. and 23% Avg.
  • Price Reduction for Core Products
  • Price Reduction in Multiple Regions
undefined. /
Connect with us on Discord
  • Secure, anonymous group chat without disturbance
  • Stay updated on campaigns, new products, and more
  • Support for all your questions
undefined. /
Free Tier
  • Start free from ECS to Big Data
  • Get Started in 3 Simple Steps
  • Try ECS t5 1C1G
undefined. /

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.