Parkour\Traverse::mapKeys PHP Method

mapKeys() public static method

Updates the keys each of the given data.
public static mapKeys ( array $data, callable $cb ) : array
$data array Data.
$cb callable Function to map keys.
return array Mapped data.
    public static function mapKeys(array $data, callable $cb)
    {
        $mapped = [];
        foreach ($data as $key => $value) {
            $mappedKey = call_user_func($cb, $value, $key);
            $mapped[$mappedKey] = $value;
        }
        return $mapped;
    }

Usage Example

 /**
  *
  */
 public function testMapKeys()
 {
     $data = ['a' => 1, 'b' => 2];
     $closure = $this->closure([[1, 'a', 'c'], [2, 'b', 'd']]);
     $expected = ['c' => 1, 'd' => 2];
     $this->assertEquals($expected, Traverse::mapKeys($data, $closure));
 }