I have the following array:
Array
(
[0] => Array
(
[event_id] => 90
[event_date] => 2012-11-29
[multi] => 1
)
[1] => Array
(
[event_id] => 86
[event_date] => 2012-11-29
[multi] => 1
)
[2] => Array
(
[event_id] => 52
[event_date] => 2012-11-30
[multi] => 0
)
)
which I am generating on the fly with the following code:
$dates = array();
$curr_date = array();
$iteration_date = null;
foreach ( $query as $q ) {
$event_id = $q->ID;
$curr_date['event_id'] = $event_id;
$curr_date['event_date'] = date('Y-m-d', get_post_meta($event_id, 'event_unix_date', true));
if ( empty($iteration_date) ) {
$iteration_date = $curr_date['event_date'];
$curr_date['multi'] = 1;
} elseif ( $iteration_date == $curr_date['event_date'] ) {
$curr_date['multi'] = 1;
} else {
$iteration_date = $curr_date['event_date'];
$curr_date['multi'] = 0;
}
array_push($dates, $curr_date);
}
This is based off a MySQL database result.
What I’m attempting to do is:
Check to see if there are arrays with the same [event_date], if so, count how many, do a special piece of code (a function is fine), and depending on what is output, set the [multi] value to 1, 2 or 3 depending on that condition.
Basic logic would be:
Check to see if there are multiple [event_date]‘s. If there are, check category on all of the matching duplicate dates. If all dates are X, populate [multi] with 1, if all dates are Y, populate with 2, if dates are mixed X & Y, populate with 3. If there is only a single date, populate with 1 or 2 depending on which category it is in.
I thought I was on the right track by just looping through the query (it is DESC by event_date), but this won’t let me check the individual entries category and populate based on that.
Can anyone point me in the right direction?
Are we to assume a sorted multidimensional array (by ascending [event_date]) every time?
If so, you could:
}
Is that what you were talking about? You can insert a call to another function where I commented one in. Question was unclear, but this is what it sounded like what you wanted.
The function parses the array given as the first parameter, checking if the second parameter is similar in each subarray, and storing them in the subarrays in a key named whatever you put for the third parameter.