简体   繁体   English

打印没有内容的数组结构?

[英]Printing the structure of an array without its contents?

I was wondering if there is a way to print just the structure of the array without the contents. 我想知道是否有一种方法只打印没有内容的数组结构。 I generally use print_r to examine the structure but because my array contains some binary data, I'd rather not use this. 我通常使用print_r来检查结构,但因为我的数组包含一些二进制数据,所以我宁愿不使用它。

<?php
    function print_no_contents($arr) {
        foreach ($arr as $k=>$v) {
            echo $k."=> ";
            if (is_array($v)) {
                echo "\n";
                print_no_contents($v);
            }
            else echo "[data]";
            echo "\n";
        }
    }
?>

*didn't test this, but should get you started. *没有测试这个,但应该让你开始。

here is array structure with data 这是带数据的数组结构

        echo printArray($your_array);

        function printArray($a,$return=true) {
                   if(!$return)
                      echo "<pre style=\"font-size:12px;\">".print_r($a,true)."</pre>";
                   else
                       return "<pre style=\"font-size:12px;\">".print_r($a,true)."</pre>";
        }

couldnt you just do 你不能这样做

foreach ($array as $structure=>$data){
  echo $structure."=><br />";
}

I like to use xdebug's var_dump() overload for all of my variable snooping. 我喜欢在我所有变量监听中使用xdebug的var_dump()重载 You can provide it with an ini setting to truncate the values that are dumped out, and it provides some sane limites to begin with (though I'm not sure what it typically does with binary data). 你可以为它提供一个ini设置来截断掉掉的值,它提供了一些理智的限制(虽然我不确定它通常用二进制数据做什么)。

ini_set('xdebug.var_display_max_data', 0);
var_dump($your_variable);

You can download it from http://xdebug.org/ 您可以从http://xdebug.org/下载它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM