PHP Array - Turning Array values into Keys

arrays, key, php

Solution

Use PHP's `array_flip` function.

On second thought, if you want the values to be null, then you might want to use `array_fill_keys`:

$out = array_fill_keys($in, null);

Problem

What is the MOST EFFICIENT way to have an array of values and turn it into an array of keys? I'd really like to avoid any foreach loop... ``` $in = array( 'red', 'green', 'blue' ); ``` INTO ``` $out = array( 'red' => NULL, 'green' => NULL, 'blue' => NULL ); ```

Original source