小编Sub*_*bie的帖子

为什么PHP日期('m',strtotime(' - 1个月'))今天无法正常工作?07/31

我有一个脚本,可以在PHP中获取当前和上个月:

$currentMonth = date('m');
//Expected:07
//Result:07
$lastMonth = date('m', strtotime('-1 months'));
//Expected:06
//Result:07
Run Code Online (Sandbox Code Playgroud)

今天恰好是7月31日或月底.这个结果是从PHP预期的吗?

使用-31天时,结果如预期:

$lastMonth = date('m', strtotime('-31 days'));
//Expected:06
//Result:06
Run Code Online (Sandbox Code Playgroud)

php date strtotime

6
推荐指数
1
解决办法
1049
查看次数

使用is_array()检测嵌套数组

现在我有以下数组:

    $test = array(
      'allow' => array(
          'access_level' => array(
             'manager',
             'admin',
          ),
      ),
   ),
Run Code Online (Sandbox Code Playgroud)

我正在做一个foreach循环:

foreach($test['allow'] as $key => $value) {
    if(is_array($key)){
       echo "Its an array within an array!";
    }
}
Run Code Online (Sandbox Code Playgroud)

但关键不是数组.我怎么能弄清楚access_level是一个数组还是只指向一个值?

php arrays cakephp

1
推荐指数
1
解决办法
310
查看次数

标签 统计

php ×2

arrays ×1

cakephp ×1

date ×1

strtotime ×1