Using array_map() for Array Transformation in PHP


Apply a callback to the elements of an array with array_map().

Source Code

$numbers = [1, 2, 3, 4, 5];
$squared = array_map(function($n) { return $n * $n; }, $numbers);
print_r($squared);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments