【问题标题】:Increment within Tax year纳税年度内的增量
【发布时间】:2014-07-31 08:41:42
【问题描述】:

我想增加财政年度(4 月至 3 月)内的月份,我目前使用的以下代码可以增加上述年份内的月份。我如何计算一个财政年度的价值。我是 PHP 新手,请帮助我。

if (isset($_REQUEST['Receipts'])) {
$months = array( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec");
$year=2009;
foreach ($months as $i=>$month) {
$monthNumber=$i+1;
$numberOfDaysInMonth=cal_days_in_month(CAL_GREGORIAN, $monthNumber, $year);
$params['Date'] = "$numberOfDaysInMonth $month $year";
}

目前我得到的输出是 2009 年的值(2009 年 1 月、2 月 9 日、3 月 9 日、4 月 9 日、5 月 9 日、6 月 9 日、7 月 9 日、8 月 9 日、9 月 9 日、10 月 9 日、11 月 9 日、12 月09) 但我想要一个财政年度,比如 2009 年 4 月、2009 年 5 月、......到.......... 2010 年 1 月、2010 年 2 月、2010 年 3 月

【问题讨论】:

  • 您面临什么问题...这是否有任何错误?
  • 不清楚。你有什么要求?
  • 我目前得到的输出是 2009 年的值(2009 年 1 月、2 月 9 日、3 月 9 日、4 月 9 日、5 月 9 日、6 月 9 日、7 月 9 日、8 月 9 日、9 月 9 日、10 月 9 日, Nov 09, Dec 09) 但我想要一个财政年度,例如 2009 年 4 月,2009 年 5 月,......到............ 2010 年 1 月,2010 年 2 月,2010 年 3 月。

标签: php


【解决方案1】:

重新排序您的月份数组以从 Apr 开始,并在处理完 Dec 后增加年份:

$months = array( "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", "Jan", "Feb", "Mar");
$year=2009;
foreach ($months as $i=>$month) {
    $monthNumber=$i+1;
    $numberOfDaysInMonth=cal_days_in_month(CAL_GREGORIAN, $monthNumber, $year);
    $params['Date'] = "$numberOfDaysInMonth $month $year";
    if ($month == 'Dec') {
        ++$year;
    }
}

顺便说一句,你每次都在重写 $params['Date'],不确定这是你想要的

【讨论】:

    猜你喜欢
    • 2011-11-13
    • 2022-06-12
    • 2016-11-04
    • 1970-01-01
    • 1970-01-01
    • 2019-08-05
    • 2020-01-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多