I was wondering if there is a better solution to this: Transform an array containing arrays with a single value into an array of one less depth. I.e.
The array prints like this:
Array
(
[0] => Array
(
[item_1] => 5
)
[1] => Array
(
[item_2] => 7
)
[2] => Array
(
[item_4] => 1
)
[3] => Array
(
[item_5] => 1
)
)
and should get transformed to print like:
Array
(
[item_1] => 5
[item_2] => 7
[item_4] => 1
[item_5] => 1
)
Right now I achieve this with this code:
$items = array(...) // retrieved from db
$counts = array();
foreach ($items as $item) {
foreach ($item as $key => $val) {
$counts[$key] = $val;
}
}
Is there a better way to combine the array items of the contained arrays into a single array?
Untested, but should work: