Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing the structure of an array without its contents?

Tags:

php

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.

like image 723
Legend Avatar asked Apr 16 '10 04:04

Legend


2 Answers

<?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.

like image 151
Austin Hyde Avatar answered Oct 10 '22 01:10

Austin Hyde


couldnt you just do

foreach ($array as $structure=>$data){
  echo $structure."=><br />";
}
like image 33
Jamie Avatar answered Oct 10 '22 01:10

Jamie