我正在尝试为我的日历应用程序创建一个相当复杂的数组。它应该包含日期、日期名称、“类型”和事件(如果有)。我已经创建了这个:
[dates] {
[22] {
[day] => [Friday]
[type] => [weekday]
}
[23] {
[day] => [Saturday]
[type] => [Weekend]
}
[24] {
[day] => [Sunday]
[type] => [Weekend]
}
}
现在我想添加另一个名为“事件”的键。我想将每天的事件添加到数组中。所以我可以得到类似的东西:
[24] {
[day] => [Sunday]
[type] => [Weekend]
[events] {
[1] {
[title] => [test event]
[description] => [my event]
[date] => [24-04-2011]
}
[2] {
[title] => [test event 2]
[description] => [my second event]
[date] => [24-04-2011]
}
}
不确定这是否有意义。
我使用以下代码创建了第一个示例:
for($i = 1; $i <= $data['days_in_curr_month']; $i++)
{
$day_info = $this->get_day_info($i, $data['current_month'], $data['current_year']);
$dates[$i]['name'] = $day_info['day_name'];
$dates[$i]['type'] = $day_info['day_type'];
}
return $dates;
然后我想通过执行以下操作来获取事件信息:
$event_info = $this->get_event_info($i, $data['current_month'], $data['current_year']);
在同一个 for 循环中。
我的 get_event_info 方法如下所示:
public function get_event_info($day, $month, $year)
{
$date = $year . "-" . $month . "-" . $day;
$this->db->where('date', $date);
$this->db->where('user_id', '1');
$query = $this->db->get('tblEvents');
$event_info = array();
foreach($query->result() as $row)
{
$event_info['events'][$row->id]['title'] = $row->title;
$event_info['events'][$row->id]['description'] = $row->description;
}
return $event_info;
}
它输出这样的数组:
Array ( [events] => Array ( [1] => Array ( [title] => Project 2 [description] => Test: Project 2 ) [2] => Array ( [title] => Illustrator [description] => Test: Illustrator 2 ) ) )
现在,我从以下位置返回 $event_infoget_events_info
to the create_dates_list
方法,但我不确定如何将事件数组添加到 $dates 数组中。
get_event_info 获取每个日期的事件(1 - 月底)。然后,我想以第二个示例中上面列出的格式将它们添加到 $dates 数组中。
我很困惑,因为这些是相当复杂的数组。提前致谢。