Efficiently Programming Using array_map in PHP

How to use array_map php in many case

According php.net , array_map php returns an array containing all the elements of array1 after applying the callback function to each one. The number of parameters that the callback function accepts should match the number of arrays passed to the array_map()

But, in my opinion, is a function array_map in php, which is useful for the efficiency of our programming structure becomes shorter and effective, particularly in the use of arrays

Structure using array_map

array array_map ( callback $callback , array $array1 [, array $… ] )

callback : Callback function to run for each element in each array.

array1 : An array to run through the callback function.

as an example using array_map 

 Implementation array_map() php frequently used are as follows 

Input Form Filtering using array_map.

With array_map() we can filtering form input.

To clean form, we do stripslashes first like follows:

With array_map we can simplify as follows :

Eliminate duplicate arrays in multidimensional array with php array_map.

Resetting the multidimensional array with array_map.

Thus the use of array_map on php, still a lot of php functions are very useful, I will discuss in other occasions

The following two tabs change content below.
This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Leave a Comment

Your email address will not be published.

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.