Hello,
I’m currently working with a series of multi-dimensional arrays, and have run into a case in which I need to convert these into a series of single-dimensional arrays. For example, given the following:
Array (
[0] => cardiff
[1] => ely-cardiff
[2] => st-fagans
[3] => peterston
[4] => llantrissant
[5] => pencoed
[6] => Array (
[0] => bridgend
[1] => Array (
[0] => tondu
[1] => cefn-cribwr
[2] => pyle
[3] => porthcawl
)
[2] => llangonoyd
[3] => maesteg
)
[7] => pyle
[8] => port-talbot
[9] => briton-ferry
)
I would like to break this apart and create a series of separate arrays, e.g.
// Array 1
Array (
[0] => cardiff
[1] => ely-cardiff
[2] => st-fagans
[3] => peterston
[4] => llantrissant
[5] => pencoed
[6] => bridgend
[7] => pyle
[8] => port-talbot
[9] => briton-ferry
)
// Array 2
Array (
[0] => bridgend
[1] => tondu
[2] => llangonoyd
[3] => maesteg
)
// Array 3
Array (
[0] => tondu
[1] => cefn-cribwr
[2] => pyle
[3] => porthcawl
)
Note, that the first value in each new array, is the first value in the nested array. The original array could potentially have several levels of nesting, so I need some sort of recursive function. This is probably covering basic programming concepts, but couldn’t find an answer elsewhere, so thought I would ask in this friendly forum
Much help appreciated!
Paul