<?php $numbers = [1, 2, 3, 4, 5]; $numbers2 = [1, 2, 3, 4, 5]; // array_map $doubled = array_map(fn($n) => $n * 2, $numbers); // array_map, passing multiple arrays $x = array_map(fn($a, $b) => $a * $b, $numbers, $numbers2); // array_filter $odd = array_filter($numbers, fn($n) => $n % 2); // array_reduce $product = array_reduce($numbers, fn($a, $n) => $a * $n, 1); print_r($doubled); print_r($x); print_r($odd); print_r($product);
To embed this project on your website, copy the following code and paste it into your website's HTML: