Sorry if a solution exists anywhere else, but I couldn't find one.
I have the following array:
$data = array(
array('a', 'b', 'c'),
array('e', 'f', 'g'),
array('w', 'x', 'y', 'z'),
);
I am trying hard to write a function that will give an array like:
a
e
w
x
y
z
f
w
x
y
z
g
w
x
y
z
b
e
w
x
y
z
f
w
x
y
z
g
w
x
y
z
c
e
w
x
y
z
f
w
x
y
z
g
w
x
y
z
The major problem here is that the number of source arrays and their lengths keep changing always. So a function should be capable of handling any data given to it.
I tried to come up with something like this:
function testfunc($data){
$arrayDepth = count($data);
foreach($data as $key=>$d){
foreach($d as $e){
echo $e . "\n";
if($key < $arrayDepth){
array_shift($data);
testfunc($data);
}
}
}
}
And the output I got was:
a
e
w
x
y
z
f
g
w
x
y
z
b
w
x
y
z
c
e
f
g
w
x
y
z
I am stuck for almost a day with no proper solution. Any help would be great! Thanks!