Making PHP var_dump() values display one line per value

前端 未结 14 1283
隐瞒了意图╮
隐瞒了意图╮ 2020-12-23 15:41

When I echo var_dump($_variable), I get one long, wrapping line with all varable\'s and values like

[\"kt_login_user\"]=>  string(8) \"teacher1\" [\"kt_lo         


        
14条回答
  •  北海茫月
    2020-12-23 16:26

    For devs needing something that works in the view source and the CLI, especially useful when debugging unit tests.

    echo vd([['foo'=>1, 'bar'=>2]]);
    
    function vd($in) {
      ob_start(); 
      var_dump($in);
      return "\n" . preg_replace("/=>[\r\n\s]+/", "=> ", ob_get_clean());
    }
    

    Yields:

    array(1) {
      [0] => array(2) {
        'foo' => int(1)
        'bar' => int(2)
      }
    }
    

提交回复
热议问题