I have an array like so:
1 => array:7 [▼
"id" => "4"
"order_code" => "BS-ORD-000000004"
"order_type" => "Mixed - Subscription"
"subscription_months" => "4"
"subscription_start_month" => Carbon {#714 ▼
+"date": "2016-11-05 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"subscription_end_month" => Carbon {#723 ▼
+"date": "2017-03-04 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"monthName" => "November"
]
2 => array:7 [▼
"id" => "4"
"order_code" => "BS-ORD-000000004"
"order_type" => "Mixed - Subscription"
"subscription_months" => "4"
"subscription_start_month" => Carbon {#721 ▼
+"date": "2016-11-05 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"subscription_end_month" => Carbon {#717 ▼
+"date": "2017-03-04 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"monthName" => "December"
]
3 => array:7 [▼
"id" => "4"
"order_code" => "BS-ORD-000000004"
"order_type" => "Mixed - Subscription"
"subscription_months" => "4"
"subscription_start_month" => Carbon {#729 ▼
+"date": "2016-11-05 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"subscription_end_month" => Carbon {#730 ▼
+"date": "2017-03-04 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"monthName" => "January"
]
4 => array:7 [▼
"id" => "4"
"order_code" => "BS-ORD-000000004"
"order_type" => "Mixed - Subscription"
"subscription_months" => "4"
"subscription_start_month" => Carbon {#732 ▼
+"date": "2016-11-05 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"subscription_end_month" => Carbon {#733 ▼
+"date": "2017-03-04 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"monthName" => "February"
]
Now what I want is to append a year to the monthName
key after adding the months from subscription_start_month
key.
Example of what I want:
2 => array:7 [▼
"id" => "4"
"order_code" => "BS-ORD-000000004"
"order_type" => "Mixed - Subscription"
"subscription_months" => "4"
"subscription_start_month" => Carbon {#721 ▼
+"date": "2016-11-05 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"subscription_end_month" => Carbon {#717 ▼
+"date": "2017-03-04 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"monthName" => "December, 2016" // <-- The current year
]
3 => array:7 [▼
"id" => "4"
"order_code" => "BS-ORD-000000004"
"order_type" => "Mixed - Subscription"
"subscription_months" => "4"
"subscription_start_month" => Carbon {#729 ▼
+"date": "2016-11-05 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"subscription_end_month" => Carbon {#730 ▼
+"date": "2017-03-04 00:00:00.000000"
+"timezone_type": 3
+"timezone": "UTC"
}
"monthName" => "January, 2017" // <-- The next year
]
I have the tried the following code, but it does not work as expected.
$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++;
}
How can I achieve that ? Kindly help me out..
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire