How to iterate date and time in PHP

We need to iterate date and time between two predefined time moments with a predefined time step.

For example 30 minutes step

$start = new \DateTime(...);
$end = new \DateTime(...);
for ($temp=$start; $temp<=$end; $temp->add(new \DateInterval('PT30M')))
{..}

1 day step

for ($temp=$start; $temp<=$end; $temp->add(new \DateInterval('P1D')))
{..}