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!