tags:

views:

102

answers:

1
$startDate = 20130201;
$date      = 20130505;
$aDates    = $this->getDates($startDate, $date);

public function getDates($startDate, $date) {
    $tmpStartDate = date("Ymd", strtotime($startDate.'+1 Day'));
    $tmpEndDate   = date("Ymd", strtotime($tmpStartDate.'+1 Month'));

    if($date >= $tmpStartDate && $date <= $tmpEndDate) {
        //return array('startDate' => $tmpStartDate, 'endDate' => $tmpEndDate);
    } else {
        $this->getDates($tmpEndDate, $date);
    }
}
+8  A: 

If the }else{ is called, nothing gets returned from the recursive call.

Try uncommenting your commented line and adding "return" to the beginning of that else clause:

return $this->getDates($tmpEndDate, $date);
Andy Shellam
Of course. I couldn't see that at all :P
Skilldrick
Damn that appears to have worked. Forgot you need to return to itself.
Cool - @user275074 if it worked for you please mark it as answered.
Andy Shellam
Good answer. @user275074: Stack Overflow relies on having its questions marked with the correct answer. You can do so by clicking the tick icon to the left of the answer under the up/down voting buttons. PS Welcome to Stack Overflow!
Andy E