- var_dump: documentation ( source)
<?php
function getLastMonth(DateTime $date)
{
//avoid side affects
$date = clone $date;
$date->modify('first day of last month');
return array(
'first' => $date->format('Y-m-d'),
'last' => $date->format('Y-m-t'),
);
}
var_dump(getLastMonth(new \DateTime()));