I have the following array:
Array
(
[key1] => 10
[key2] => 7
[key3] => 8
)
I want to convert it to the following structure:
Array
(
[0] => Array
(
[section] => key1
[quantity] => 10
),
[1] => Array
(
[section] => key2
[quantity] => 7
),
[2] => Array
(
[section] => key3
[quantity] => 8
)
)
I tried to use array_map
function, but inside the closure I get only a value without a key. Please, suggest me the easiest way to do it, without foreach
.
Update
I think using foreach requires creation of an additional variable which makes the code messy and resource requiring.