Pet*_*ore 2 php variables datetime reference function
我创建了一个函数,该函数根据第一个日期时间创建两个日期时间:
// initial datetime (for test)
$dt = new \Datetime;
$dt->setDate(2012, 9, 5);
// splitting into 2 different datetimes
$dates = $this->defineLimitsByDate($dt);
// $dates[0] = 2011-07-01
// $dates[1] = 2012-09-01
Run Code Online (Sandbox Code Playgroud)
目前,一切都还好。现在,我将这些日期时间传递到另一个函数中,在该函数中,我使用循环while递增第一个日期,直到到达第二个日期:
// now I use the 2 datetimes into a function...
$dateKeys = $this->generateDateKeys($dates[0], $dates[1]);
// and the function seems to modify them outside itself !
// $dates[0] = 2012-10-01
// $dates[1] = 2012-09-01
Run Code Online (Sandbox Code Playgroud)
看来我的函数内的 while 循环generateDateKeys没有在本地修改参数。它更改函数外部 $dates 的值。但我从不使用引用传递。
谁能启发我一下吗?
| 归档时间: |
|
| 查看次数: |
1240 次 |
| 最近记录: |