It's probably beginner question but I'm going through documentation for longer time already and I can't find any solution. I thought I could use implode for each dimension and then put those strings back together with str_split
to make new simple array. However I never know if the join pattern isn't also in values and so after doing str_split
my original values could break.
Is there something like combine($array1, $array2)
for arrays inside of multi-dimensional array?
In PHP>=5.3 and based on Luc M's answer (the first one) you can make use of closures like this
I love this because I don't have to surround the function's code with quotes like when using create_function()
Using higher-order functions (note: I'm using inline anonymous functions, which appeared in PHP 5.3):
REF: http://php.net/manual/en/function.call-user-func-array.php
Here is another solution (works with multi-dimensional array) :
Given multi-dimensional array and converting it into one-dimensional, can be done by unsetting all values which are having arrays and saving them into first dimension, for example:
Also documented: http://www.phpro.org/examples/Flatten-Array.html
A non-recursive solution (but order-destroying):