In PHP, how do I map arrays with PHP 8+ features?

In PHP 8 and later, mapping arrays can be accomplished using various features including the `array_map` function. Below is an example demonstrating how to map an array with a callback function.

PHP 8, array_map, array functions, callback functions, programming
This example shows how to use the `array_map` function in PHP 8+ to manipulate array elements using a callback function.

$numbers = [1, 2, 3, 4, 5];
$squared = array_map(fn($num) => $num ** 2, $numbers);

print_r($squared); // Outputs: Array ( [0] => 1 [1] => 4 [2] => 9 [3] => 16 [4] => 25 )
    

PHP 8 array_map array functions callback functions programming