Call us now! 8130-90-5320 | info@lohiyait.com | Find our Location
Array Map in PHP
admin March 27, 2021 Category: PHP Views: 637
Array ma in php

Applies the callback to the elements of the given arrays

The array_map() function sends each value of an array to a user-made function, and returns an array with new values, given by the user-made function.

Syntax

 
array_map ( callable|null $callback , array $array , array …$arrays ) : array

Callback

A callable to run for each element in each array.
null can be passed as a value to callback to perform a zip operation on multiple arrays. If only array is provided, array_map() will return the input array.

Array

An array to run through the callback function.arraysSupplementary variable list of array arguments to run through the callback function.

Example

<?Php

function cube($n)
{
return ($n * $n * $n);
}

$a = [1, 2, 3, 4, 5];
$b = array_map(‘cube’, $a);
print_r($b);
?>