I have a simple array where key is always followed by the value:
Array (
[0] => x
[1] => foo
[2] => y
[3] => bar
)
which I would like to convert to associative one:
Array (
[x] => foo
[y] => bar
)
What is the easiest and most elegant way to do this?
To be memory efficient, and less calculations.
If the $input array has odd number of values, the last value will be NULL.
$result = array();
while (count($input)) {
$result[array_shift($input)] = array_shift($input);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With