I'm having trouble trying to figure out how to achieve this programming challenge in my Zend Framework application:
I need to create an array that looks like this:
$array = array(
0 => stdClass()->monthName
->monthResources = array()
1 => stdClass()->monthName
->monthResources = array()
);
This is the original array I have to work with:
$resources = array(
0 => Resource_Model()->date (instance of Zend_Date)
1 => Resource_Model()->date
2 => Resource_Model()->date
//etc...
);
The original array ($resources
) is already sorted by date (descending) so I need to create an array where the resources are grouped by month. I only want the months that have resources, so if the resources skip a month, there shouldn't be a stdClass
object for that month in the final array.
I also want this to process quickly, so any advice on optimizing the code (and still being readable) would be great. How can I achieve this?