最新消息:20210816 当前crifan.com域名已被污染,为防止失联,请关注(页面右下角的)公众号

【已解决】PHP的error_log中如何打印输出数组(array)变量

PHP crifan 9058浏览 0评论

【问题】

想要在php的erro_log中输入一个array类型变量。

但是使用:

error_log(print_r($array_data));

输入的内容却是1

【解决过程】

1.经过一番折腾,最后参考:

Human readable error_log

写成:

error_log(print_r($array_data, 1));

就可以正常输入需要的信息了:

[26-Oct-2012 08:27:05] Array
(
    [name] => _thumb.png
    [type] => image/png
    [bits] => ʐNG

 

其实,后来也才看到,原来之前的这里:

http://fuelyourcoding.com/simple-debugging-with-wordpress/

就已经给出了相应的代码了:

if(!function_exists('_log')){
  function _log( $message ) {
    if( WP_DEBUG === true ){
      if( is_array( $message ) || is_object( $message ) ){
        error_log( print_r( $message, true ) );
      } else {
        error_log( $message );
      }
    }
  }
}

 

【总结】

error_log(print_r($array_data, 1));

就可以输入可读的array类型变量了。

转载请注明:在路上 » 【已解决】PHP的error_log中如何打印输出数组(array)变量

发表我的评论
取消评论

表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
82 queries in 0.226 seconds, using 22.11MB memory