Pretty simple:
// turn array('foo', 'bar', 'hello', 'world'); // into array('foo' => 'bar', 'hello' => 'world');
Now I am using:
do{ $arrayOut[current($arrayIn)] = next($arrayIn); }while(next($arrayIn));
I am wondering if there is a way to do this without the $arrayOut intermediate variable. I could write a function, but this is the only use case, and I'm trying to keep the script uncluttered. I'm just wondering if there is something that I missed in the documents that would serve this purpose.
Values come from the routing path:
route/to/controller/action/key1/value1/key2/value2
It exploded and, in the end, after using other components, I was left with ('key1', 'value1', 'key2', 'value2', ...)
Thank you for your understanding and suggestions. Long Ears won this one for a brief approach, which when expanded to more than "1 line" is not terribly cryptic (I don't think so, at least)
However, with regard to the Long Ears proposal, perhaps my desire for semantically accurate code with minimal detail became better than me, and I chased daisies, trying to preserve my variable “pollutant-free” scope to rephrase myself.
source share