I have some basic data coming from a csv upload, the table is formatted like so:
| Cost 1 | Cost 2 | Cost 3 |
|---|---|---|
| 5 | 12 | 5 |
| 1 | 13 | 9 |
| 9 | 0 | 1 |
The data saves to the database and using array_chunk I have an array that looks like this (I will need to loop through these later)
array(
[0] => Array
(
[Cost 1] => 5
)
[1] => Array
(
[Cost 2] => 12
)
[2] => Array
(
[Cost 3] => 3
)
)
I want to modify the array to read the keys as values instead, so the final array would look like this with the column title saving in every instance:
array(
[0] => Array
(
[cost] => Cost 1
[demand] => 5
)
[1] => Array
(
[cost] => Cost 2
[demand] => 12
)
[2] => Array
(
[cost] => Cost 3
[demand] => 3
)
)
I know I can use array_keys and array_values to target each, but can't quite get my head around how I'd use that to create the above.