I have a question here. Let’s say I have an array of the form:
Array
(
[0] => Array
(
[0] => Array
(
[A] => Array
(
[id] => 1
[firstname] => John
[lastname] => Smith
[email] => jsmith@gmail.com
)
[B] => Array
(
)
)
)
[1] => Array
(
[0] => Array
(
[A] => Array
(
[id] => 2
[firstname] => Tommy
[lastname] => Tom
[email] => ttom@gmail.com
)
[B] => Array
(
)
)
)
)
How can I replace the index of the outer array by the index of the inner array in order to have an array like this:
Array
(
[0] => Array
(
[A] => Array
(
[id] => 1
[firstname] => John
[lastname] => Smith
[email] => jsmith@gmail.com
)
[B] => Array
(
)
)
[1] => Array
(
[A] => Array
(
[id] => 2
[firstname] => Tommy
[lastname] => Tom
[email] => ttom@gmail.com
)
[B] => Array
(
)
)
)
Thanks in advance!
You have to loop through the arrays and create a new array based on the inner values.
Here,
$out_array[$k]keeps the original top-level array keys, andarray_shift($v)says to dig down one level for the values (taking the value at the first element in the mid-level array usingarray_shift, and applying it as the value for the new array).