Don't know this question is asked before or not, cannot find after lot of searching.
My array looks like this,
array(3) {
[0]=>
array(2) {
[0]=>
array(1) {
["userId"]=>
string(3) "421"
}
[1]=>
array(1) {
["userId"]=>
string(3) "329"
}
}
[1]=>
array(1) {
[0]=>
array(1) {
["userId"]=>
string(3) "329"
}
}
[4]=>
array(2) {
[0]=>
array(1) {
["userId"]=>
string(3) "329"
}
[1]=>
array(1) {
["userId"]=>
string(3) "421"
}
}
}
What I want is,
array(1) {
[0]=>
array(5) {
[0]=>
array(1) {
["userId"]=>
string(3) "421"
}
[1]=>
array(1) {
["userId"]=>
string(3) "329"
}
[2]=>
array(1) {
["userId"]=>
string(3) "329"
}
[3]=>
array(1) {
["userId"]=>
string(3) "329"
}
[4]=>
array(1) {
["userId"]=>
string(3) "421"
}
}
}
I have tried with array_merge
, array_combine
and a lot of foreach()
loops. But didn't get luck for desired output.
Don't know how to do this. Please help.
You can flatten your array like this:
UPDATE: If you don't want to use
RecursiveIteratorIterator
, the you can also do it like this usingarray_walk_recursive()
:This will give you the output as:
Hope this helps!