5
1
NOTE: This question was migrated from https://stackoverflow.com/q/27134588/1442685
PHP QUESTION
Almost purely out of curiousity, how can I take an array like this:
array( 'fruit' => 'banana', 'drink' => 'milk')
And convert it to an array like this:
array( 'fruit=banana', 'drink=milk')
Requirements
- Cannot use anonymous functions
- If needed, can only use
array_*
functions that accept callable if that callable is native to PHP - Must be a one-liner solution
This is not for a class. I'm curious to see how clever one can be with array functions. Given the requirements, is it possible?
2
Hello, welcome to PPCG :) Presumably, you want the shortest code to do this? If so, I recommend tagging your problem [tag:code-golf] (Currently this lacks a winning criterion and could be closed). Consider using our sandbox for future questions.
– FryAmTheEggman – 2014-11-25T19:34:50.743Thanks @FryAmTheEggman - I've updated my tag, and am reading up on the sandbox now. – Rick Buczynski – 2014-11-25T19:36:19.310
1No problem :) Just some nit-picking, you might want to edit your title to reflect the rules i.e. "Shortest Code to translate a PHP array." You also shouldn't say "preferably"; either force one-liners, or don't. Also, just like SO, wait a while before accepting ;p – FryAmTheEggman – 2014-11-25T19:43:07.473
Got it. Will do. – Rick Buczynski – 2014-11-25T19:43:45.460
1This question isn't migrated: it's cross-posted, and it's already been answered on SO. – Peter Taylor – 2014-11-25T20:29:12.567
Yea, I don't know how to do that/I don't have authority to. How do suggest I handle this? – Rick Buczynski – 2014-11-25T20:36:49.983
3If you want to migrate a question from one site to another within the Stack Exchange network, you should use a custom flag. But 99% of the time you should pay no attention to people on SO who say that a question would be a better fit on PPCG, because most of them have no idea what's on topic here and what isn't. – Peter Taylor – 2014-11-25T22:56:07.607