0

我正在使用 FullCalendar jquery 插件在我的网站上显示日历。我能够硬编码一些在我的日历上显示得很好的值。格式应为:

echo json_encode(array(

        array(
            'id' => 1136,
            'title' => "Understanding Health-Care Regulations (Part II) and COBRA Compliance Strategies",
            'start' => "2011-11-17",
            'url' => "/www/conferences/conference.php?ID=1136"
        ),

        array(
            'id' => 1154,
            'title' => "Making the Most of your Membership",
            'allDay' => false,
            'start' => "Wed, 18 Nov 2011 11:00:00 EST",
            'url' => "/www/conferences/conference.php?ID=1154"
        ),
        array(
            'id' => 1137,
            'title' => "2011 Annual Human Resources Conference",
            'start' => "2011-11-29",
            'url' => "/www/conferences/conference.php?ID=1137"
        ),


    ));

当试图模仿这个数组结构时,我正在使用这个:

$conferences = dbStoredProc('cp_meeting_get_list_new');
$events = array();

foreach ($conferences as $c){
    $push = array(
        'id'        => $c['ID'],
        'title'     => $c['name'],
        'start'     => date("Y", $c['epochDate']) . "-" . date("M", $c['epochDate']) . "-" . date("d", $c['epochDate']),
        'url'       => '/events/details.php?id' . $c['ID'],
    );
    array_push($push, $events);
}
echo json_encode($events);

当我回显我的$events变量时,我得到[].

有任何想法吗?

4

4 回答 4

6
array_push($push, $events);

应该

array_push($events, $push);

要不就

$events[] = $push;
于 2012-08-17T13:43:53.400 回答
1

正如 xdazz 所说,您需要将参数切换为array_push. 或者,使用 [] 语法将项目推送到数组的末尾:

$events[] = $push;

此外,您可以将多个格式说明符传递给date,因此您的起始行可以写为:

date("Y-M-d", $c['epochDate']),   
于 2012-08-17T13:47:19.233 回答
1

你最好只使用将数据附加到数组中

$events[] = $push;

它比必须查找参数的顺序更快,更不容易混淆。

于 2012-08-17T13:44:59.880 回答
0

你的 PHP 有缺陷。尝试这个:

$conferences = dbStoredProc('cp_meeting_get_list_new');
$events = array();

foreach ($conferences as $c){
   $events[] = array(
       'id'        => $c['ID'],
       'title'     => $c['name'],
       'start'     => date("Y-M-d", $c['epochDate']),
       'url'       => '/events/details.php?id' . $c['ID']
    );
}
echo json_encode($events);
于 2012-08-17T13:47:14.420 回答