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; }
/** * */ 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)); }