Verification: a143cc29221c9be0

Php array invert keys and values

Содержание

ES6 version

const example = { a: 'foo', b: 'bar' };

const flipped = Object.entries(example)
  .reduce((obj, [key, value]) => ({ ...obj, [value]: key }), {}); 

// flipped is {foo: 'a', bar: 'b'}