gpt4 book ai didi

php - 在 CodeIgniter 中将数组与 Calendar 类一起使用

转载 作者:搜寻专家 更新时间:2023-10-31 21:17:24 25 4
gpt4 key购买 nike

我正在尝试为我的日历应用程序创建一个相当复杂的数组。它应该包含日期、日期名称、“类型”和事件(如果有的话)。我已经创建了这个:

[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 ) ) )

现在,我将 get_events_info 中的 $event_info 返回给 create_dates_list 方法,但我不确定如何将我的事件数组添加到 $dates大批。

get_event_info 获取每个日期(1 - 月底 -)的事件。然后,我想按照上面第二个示例中列出的格式将它们添加到我的 $dates 数组中。

我很困惑,因为这些是相当复杂的数组。提前致谢。

最佳答案

我认为您需要做的就是(例如):

 $append_events = get_event_info($day, $month, $year);
$array['dates']['1']['event'] = $append_events['events'];

然后您可以访问您的元素:

 $array['dates']['1']['event'][$id]['title']    
$array['dates']['1']['event'][$id]['description']

关于php - 在 CodeIgniter 中将数组与 Calendar 类一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5764998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com