public function map(array $array, callable $callback): array
    {
        $result = [];
        foreach ($array as $key => $element) {
            $result[$key] = $callback($element, $key);
        }
        return $result;
    }
public function map(array $array, callable $callback): array
    {
        $result = [];
        foreach ($array as $key => $element) {
            $result[$key] = $callback($element, $key);
        }
        return $result;
    }
public function map ( array $ array , callable $ callback ) : array { $ result = [ ] ; foreach ( $ array as $ key => $ element ) { $ result [ $ key ] = $ callback ( $ element , $ key ) ; } return $ result ; }
Apply the callback to each element of the array, passing each element and key as arguments

Examples::

Array.map([1, 2, 3, 4], x => x * x)
Array.map([1, 2, 3, 4], (x, index) => x * index)

@param array $array Array of elements to map
@param callable $callback Callback to apply for each element, current value and key will be passed as arguments
@return array The array with callback applied, keys will be preserved
Apply the callback to each element of the array passing each element and key as arguments