PHP在while循环中将日期('Y-m-d',strtotime(x天'))减少(x-1)
问题描述:
I'm trying to decrease a counter variable (x) within this date function:
date('Y-m-d', strtotime(x days'))
in a while loop like this:
$Today = date('Y-m-d', strtotime('-1 days'));
output thus far: 2015-06-25
$x = -1;
while ($row = mysql_fetch_array($result1)) {
$Today = date('Y-m-d', strtotime('$x days'));
...
$x = $x - 1;
}
desired output on next iteration of while loop: 2015-06-24 and so on ...
我正在尝试减少此日期函数中的计数器变量(x): p> \ n
date('Ym-d',strtotime(x days'))
code> pre>
在这样的while循环中: p>
$ Today = date('Ym-d',strtotime(' - 1天'));
code> pre>
输出因此 far:2015-06-25 p>
$ x = -1;
while($ row = mysql_fetch_array($ result1)){
$ Today = date ('Ym-d',strtotime('$ x days'));
...
$ x = $ x - 1;
}
code> pre> \ n
while循环的下一次迭代所需的输出:2015-06-24等等...... p>
div>
答
What you have already will work, except that it has to be done with a double quoted string to interpolate the variable, as in strtotime("$x days")
– @Michael Berkowski