【发布时间】:2016-11-05 07:14:06
【问题描述】:
在我的 Laravel 5.1 应用程序中,我有一个订阅功能。它在一定程度上有效,但不是我想要的..
场景:用户在 2016 年 10 月订阅了 6 个月。因此,数组将如下所示:
[
"subscription_months" => 6
"subscription_start_month" => "01-10-2016" // <-- will be carbon instance
"subscription_end_month => "31-03-2017" // <-- will be carbon instance
"monthName" => "October"
]
上面我展示的数组只有1个月..数组中还有5个元素..
我想要的是,我想在monthName 之后附加Year
所以,它看起来像这样。
[
[
"monthName" => "October, 2016" // <-- for 1st month
]
[
"monthName" => "November, 2016" // <-- for 2nd month
]
[
"monthName" => "December, 2016" // <-- for 3rd month
]
[
"monthName" => "January, 2017" // <-- for 4th month
]
[
"monthName" => "February, 2017" // <-- for 5th month
]
[
"monthName" => "March, 2017" // <-- for 6th month
]
]
到目前为止我尝试过的代码是:
$startMonthForMixed = $invoice->subscription_start_date->month;
for($i = 0; $i < $invoice->subscription_months; $i++) {
$convertedInvoices[] = [
'id' => $invoice->id,
'order_code' => $invoice->order_code,
'order_type' => 'Mixed - Subscription',
'subscription_months' => $invoice->subscription_months,
'subscription_start_month' => $invoice->subscription_start_date,
'subscription_end_month' => $invoice->subscription_end_date,
'monthName' => date("F", mktime(0, 0, 0, $startMonthForMixed, 01)) . ", " . Carbon::now()->addYear()
];
$startMonthForMixed++;
}
有人可以帮忙吗?提前致谢。
【问题讨论】:
-
您想要将 monthName 属性与所有其他属性一起使用吗?或者作为一个只有monthNames的子数组,它驻留在具有其他属性的记录中?
-
@trincot 我需要 monthName 属性以及所有其他属性.. 但你知道吗,它们中的任何一个都对我有用..
-
@splash58 你不认为
date("F, Y");会返回当前时间戳的年份和月份吗?? -
@SaiyanPrince 为什么不呢? - eval.in/599829我好像没看懂问题
标签: php arrays date laravel-5.1 php-carbon