Question and answer is powered by AnsPress.io
I want print last 12 moths in PHP using dates.
e.g: 2018-12 , 2018- 11 .please add sample code in description.
Here is the answers
$months = []; for ($i = 1; $i <= 12; $i++) { $months[] = date("Y-m", strtotime( date( 'Y-m-01' )." -$i months")); } print_r($months)