Reorganizing an array: odd entries as KEY, even entries as VALUE

A simple way would be to loop over the first array two at a time, building the associative structure as you go.


$array = array("greeting", "hello", "question", "how-are-you", "response", "im-fine");

$assoc = array();
foreach (array_chunk($array, 2) as $pair) {
	list($key, $value) = $pair;
	$assoc[$key] = $value;
}

var_export($assoc);

/*
array (
  'greeting' => 'hello',
  'question' => 'how-are-you',
  'response' => 'im-fine',
)
*/

There are likely ways of doing this in one line of code but the above should be nice and clear in what it is doing. (: