Mapping Array Elements in PHP


Apply a function to every element of an array, useful for transforming array values.

Source Code

$squared = array_map(function($n) { return $n * $n; }, $numbers);
print_r($squared);
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments