I have an array that looks something like this:
Array
(
[apple] => Array
(
[0] => 689795
[1] => September 2012
[2] => 689795
[3] => September 2012
[4] => 1113821
[5] => June 2013
[6] => 1122864
[7] => July 2013
)
[pear] => Array
(
[0] => 1914898
[1] => September 2012
[2] => 1914898
[3] => September 2012
[4] => 1914646
[5] => September 2012
[6] => 1914898
[7] => September 2012
)
)
What I want to do is loop through the "apple" element and output something like this:
['September 2012', 689795],
['September 2012', 689795],
['June 2013', 1113821],
['July 2013', 1122864],
How can I accomplish this? So my main goal is to organize the dates and values together.
My array data is much longer than the example above, but I just need help in order to get a working code to loop through and echo something like the example above.
I've tried using foreach
, however I can't get it to work. I'm fairly new to PHP.
reset
& 2each()
calls in a loop seems handy oldschool,foreach(array_chunk($array['apple'],2) as $combo){}
is also a possibility. – Wrikken Aug 13 '13 at 21:57