zoukankan      html  css  js  c++  java
  • php在没用xdebug等调试工具的情况下如何让调试内容优雅地展现出来?--php数组格式化

      不知道各位猿猿们有没有碰到过类似的情况。装的PHP环境没有xdebug,而又经常用到数组。调试的时候也需要经常查看数组的结构和字段内容,用var_dump打印出来的数组内容总是杂乱无章。实在无法忍受,因而网上找了个格式化数组的方法,分享给大家。也再次感谢可爱的前辈们。

    /**
    * [dump_array 将数组内容格式化输出]
    * @param array $vars [数组]
    * @param string $label [分隔符]
    * @param boolean $return [是否返回结果]
    * @return [type] [description]
    */
    function dump_array($vars, $label = '', $return = false) {
      if (ini_get('html_errors')) {
        $content = "<pre>
    ";
        if ($label != '') {
          $content .= "<strong>{$label} :</strong>
    ";
        }
        $content .= htmlspecialchars(print_r($vars, true));
        $content .= "
    </pre>
    ";
      } else {
        $content = $label . " :
    " . print_r($vars, true);
      }
      if ($return) { return $content; }
      echo $content;
      return null;
    }

    用上它,打印出来的数组不再是一坨shit了,而是优雅抚媚地展现在你的面前。

  • 相关阅读:
    linux
    查看字符的编码数字
    各种语系的unicode对应以及local编码方式
    Unicode字符集,各个语言的区间
    深入理解Python的字符编码
    php 快排
    归并排序
    检测到在集成的托管管道模式下不适用的 ASP.NET 设置的解决方法
    分布式缓存MemcacheHelper
    单例模式
  • 原文地址:https://www.cnblogs.com/rwxwsblog/p/4490951.html
Copyright © 2011-2022 走看看