$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);
}
}
views:
102answers:
1
+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
2010-02-18 11:27:14
Of course. I couldn't see that at all :P
Skilldrick
2010-02-18 11:28:44
Damn that appears to have worked. Forgot you need to return to itself.
2010-02-18 11:29:35
Cool - @user275074 if it worked for you please mark it as answered.
Andy Shellam
2010-02-18 11:35:19
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
2010-02-18 11:41:00