Home  >  Article  >  Backend Development  >  [php learning] array_map() function--calling callback function to process array data

[php learning] array_map() function--calling callback function to process array data

little bottle
little bottleOriginal
2019-04-18 10:19:262548browse

In the previous article, I shared an array_column() function with you. In this article, the editor will take you to learn another function that processes arrays - the array_map() function, which can efficiently call the callback function to process the values ​​of the array. If you are interested, please come and learn it.

array_map() function

Function:

Apply the user-defined function to each value in the array and return An array with new values ​​after the user-defined function is applied.

The number of parameters accepted by the callback function should be the same as the number passed to The array_map() function has the same number of arrays.

Syntax:

array_map(myfunction,array1,array2,array3...)

(Tip: You can input one or more arrays to the function.)

Usage scenario:

When you need to process each value in the array, for example, you need to remove spaces from the value of the array, or change all uppercase letters to lowercase

Example:

Look at the output:

Summary:

array_map is very convenient to use. You can call the callback function to process the value of the array.

If you don’t want to take any detours, please pay attention to the PHP Chinese website. There are more PHP video tutorials waiting for you to learn!

The above is the detailed content of [php learning] array_map() function--calling callback function to process array data. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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