我不知道我是否能够以可能被理解的方式提出我的问题,但我会尝试。
我有这个 php 代码,我有兴趣从 while 循环中“取出”最后一个变量!
$c= "2040-01-01 12:00:00";
$d= "2040-01-02 12:00:00";
$date_3 = date("Y-m-d g:i:s", strtotime("$c"));
$date_4 = date("Y-m-d g:i:s", strtotime("$d"));
$results = array($date_1);
$i = $date_3;
while ($i <= $date_4) {
$i = date("Y-m-d g:i:s", strtotime($i));
array_push($results, $i);
$k= $i . "\n";
$chunks = str_split($k, 19);
$nexstring = join('\')', $chunks);
$cane = implode(', (\'', str_split($nexstring, 21));
echo $cane; // OUTPUTS -> 2040-01-01 12:00:00'), (' 2040-01-02 12:00:00'), ('
$i = date("Y-m-d g:i:s",strtotime("+1 day", strtotime($i)));
}
echo $cane; // OUTPUTS -> 2040-01-02 12:00:00'), ('
现在我的问题是
为什么 $cane 在 while{} 之外向我回显一些不同的东西,我应该如何将这个变量存储在 while{} 之外是相同的?