I have the following array:
Array
(
[Banana] => Array
(
[0] => Array
(
[0] => 57
)
[1] => Array
(
[0] => 58
)
[2] => Array
(
[0] => 59
)
)
)
Does PHP have a magic function to return something like this:
Array
(
[Banana] => 57,58,59
)
Thanks.
2
Answers
I don’t recognize any magic function like this but you can easily achieve it using the following:
How it works:
implode
function,array_combine
function.The implode function is used to join elements of an array with a delimiter in between them.
In your case, you want to iterate over the elements of the outer array and replace their contents with a string of comma separated values, correct?
Alternatively, you could use array_map.