public static function mapKeys(callable $function, array $array)
    {
        $new_array = array();
        foreach ($array as $key => $value) {
            $result = call_user_func($function, $value, $key);
            if (is_array($result)) {
                if (1 === count($result)) {
                    // Only returned a value, no key, so keep existing key.
                    $new_array[$key] = array_shift($result);
                } elseif (2 === count($result)) {
                    // Returned a key and a value, so set a new key.
                    $new_array[array_shift($result)] = array_shift($result);
                }
            }
            unset($result);
        }
        return $new_array;
    }
public static function mapKeys(callable $function, array $array)
    {
        $new_array = array();
        foreach ($array as $key => $value) {
            $result = call_user_func($function, $value, $key);
            if (is_array($result)) {
                if (1 === count($result)) {
                    // Only returned a value, no key, so keep existing key.
                    $new_array[$key] = array_shift($result);
                } elseif (2 === count($result)) {
                    // Returned a key and a value, so set a new key.
                    $new_array[array_shift($result)] = array_shift($result);
                }
            }
            unset($result);
        }
        return $new_array;
    }
public static function mapKeys ( callable $ function , array $ array ) { $ new_array = array ( ) ; foreach ( $ array as $ key => $ value ) { $ result = call_user_func ( $ function , $ value , $ key ) ; if ( is_array ( $ result ) ) { if ( 1 === count ( $ result ) ) { // Only returned a value, no key, so keep existing key. $ new_array [ $ key ] = array_shift ( $ result ) ; } elseif ( 2 === count ( $ result ) ) { // Returned a key and a value, so set a new key. $ new_array [ array_shift ( $ result ) ] = array_shift ( $ result ) ; } } unset ( $ result ) ; } return $ new_array ; }
array_map with keys OR array_walk but functional

The called function receives two arguments: `$key` & `$value`.

If the called function returns an array with a single value, that single value will be inserted into the new
array at the position of the original key.

If the called function returns an array with two values, the first value used as a *new* key in the new array,
and second value is used as the value in the new array.

**WARNING**

And returns value other than an array with one or two values will be ignored! This can be useful (i.e. to
clean up an array) but you should be aware of it.

@param callable $function
@param array    $array
@return array
array_map with keys OR array_walk but functional