1

私はコードを使用しています:

$old_month = strtolower(date("m", mktime(date('H'), date('i'), date('s'), (date('m')-12),date('d'), date('Y'))));
$old_year = strtolower(date("Y", mktime(date('H'), date('i'), date('s'), (date('m')-12), date('d'), date('Y'))));


if ( $profile_stats['month'] < $old_month && $profile_stats['year'] == $old_year
|| $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) 

If ループは先月の値を取得する必要があります。つまり、今は 10 月です。9

どうすればそれを達成できますか。

解決策を提案してください。

4

2 に答える 2

2

これを使って

$old_month = strtolower(date("m", strtotime("lastmonth"));


if ( $profile_stats['month'] < $old_month && $profile_stats['year'] == $old_year
|| $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) 

する必要があります

if ( strtotime($profile_stats['month']) < strtotime($old_month) && strtotime($profile_stats['year']) == strtotime($old_year)
|| $profile_stats['month'] == date('m') && $profile_stats['year'] == date('Y') ) 
于 2012-10-18T18:29:58.870 に答える
0

月数から 12 を引いているようです。そうすれば去年に間に合います。

英語を使ってみてください -strtotime驚くほどうまく処理できます:

$last_month = strtotime("-1 month");
list($old_month,$old_year) = explode("-",date("m-Y",$last_month));
于 2012-10-18T18:31:56.063 に答える