计算总夜数

时间:2014-07-17 19:28:54

标签: php zend-framework

我有这个代码可以帮助我,因为它按天计算总价但我需要按夜间计算吗?

foreach($roomCalendar_info  as $roomCalendar_info_key   => $roomCalendar_info_arr)
{
    $room_price_sum += $this->view->price($roomCalendar_info_arr['room_price']) ;
    $room_item_details .= '<tr>';
    $room_item_details .= '<td style="line-height: 20px;">';
    $room_item_details .= $roomCalendar_info_arr['calendar_date'];
    $room_item_details .= '</td>';
    $room_item_details .= '<td style="line-height: 20px;">';
    $room_item_details .= $currencySymbol.' '.number_format($this->view->price($roomCalendar_info_arr['room_price']), 2, '.', ',').' '.$currencyShortName;
    $room_item_details .= '</td>';
    $room_item_details .= '</tr>';
}

$sub_total += $room_price_sum ;         
$cd++;  
由于给出了答案,

现在已经解决了

1 个答案:

答案 0 :(得分:0)

听起来你不想将最后一天的费率加到总额中,因为它的结账日。为了实现这一点,您需要能够检测何时处理循环中的最后一天。这应该适合你:

// Get the key of the last day
$roomCalendar_info_key_last_day = array_pop(array_keys($roomCalendar_info));

foreach($roomCalendar_info as $roomCalendar_info_key => $roomCalendar_info_arr)
{
    // Only add to the total if this is not the last day
    if ($roomCalendar_info_key != $roomCalendar_info_key_last_day)
        $room_price_sum += $this->view->price($roomCalendar_info_arr['room_price']) ;
    $room_item_details .= '<tr>';
    $room_item_details .= '<td style="line-height: 20px;">';
    $room_item_details .= $roomCalendar_info_arr['calendar_date'];
    $room_item_details .= '</td>';
    $room_item_details .= '<td style="line-height: 20px;">';
    $room_item_details .= $currencySymbol.' '.number_format($this->view->price($roomCalendar_info_arr['room_price']), 2, '.', ',').' '.$currencyShortName;
    $room_item_details .= '</td>';
    $room_item_details .= '</tr>';
}

$sub_total += $room_price_sum ;
$cd++;