$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);
}
}
Asked
Active
Viewed 342 times
1

Skilldrick
- 69,215
- 34
- 177
- 229
-
1what is it supposed to do? what does it do instead? does it throw any errors? or exceptions? – Marius Feb 18 '10 at 11:15
-
The uncommented bit should be uncommented and still doesn't work – Feb 18 '10 at 11:15
-
Because it does not know what it should do. Ok, seriously: What are you trying to achieve and what is the (bogus) result produced by your function? – soulmerge Feb 18 '10 at 11:16
-
I'm trying to add a day to start and a month to end each time and detect if $date lies between the two, if it does, return the $tmpStartDate and $tmpEndDate. – Feb 18 '10 at 11:23
1 Answers
8
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
- 15,403
- 1
- 27
- 41
-
-
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 Feb 18 '10 at 11:41