Source Code:
(back to article)
<?php // Example 1 $numbers = [1, 2, 3, 4, 5]; $sum = array_reduce($numbers, fn($carry, $number) => $carry + $number); echo $sum . PHP_EOL; // Output: 15 // Example 2 $names = ["John", "Maryjane", "Paul", "Jane"]; $filteredNames = array_filter($names, fn($name) => strlen($name) > 4); print_r($filteredNames); // Output: Array ([1] => Maryjane )
Result:
Report an issue