PHP output of a multidimensional associative array

I have a multidimensional associative array. How can I display it so that everything is shown on the screen?

The array is something like this:

$arr[Ханин]=($arr1[Иван]=19);
$arr[Остроух]=($arr1[Ольга]=18);
$arr[Кульбацкая]=($arr1[Любовь]=25) и т.д.

var_dump($arr); выводит вот так: 
array(3) { ["Ханин "]=> string(4) "19 " ["Остроух "]=> string(4) "18 " ["Иван "]=> string(4) "19 " }

print_r($arr); Вот так:
Array ( [Ханин ] => 19 [Остроух ] => 18 [Иван ] => 19 ) array(3) { ["Ханин "]=> string(4) "19 " ["Остроух "]=> string(4) "18 " ["Иван "]=> string(4) "19 " }

Is it possible to somehow output it by the tree type? What would look like something like this:

 [Ханин](
           [Иван] => 19)
[Остроух](
           [Ольга] => 18)
[Кульбацкая](
           [Любовь] => 25)
Author: Apo-S, 2013-12-07

4 answers

echo '<pre>';
print_r($array);
echo '</pre>';
 6
Author: dlarchikov, 2013-12-07 10:55:44

Will that do?"

function buildtree($in,$pre="array")    {
    if(is_array($in)){
        foreach($in as $key=>$value){
            buildtree($value,$pre.'-'.$key);
        };
    }
    else{
        echo $pre.':'.$in.'<br>';
    };
};
 3
Author: uk141, 2016-11-18 08:42:15

You can wrap the result in the

 tag, as shown below.

echo '<pre>'.print_r($array, true).'</pre>';
 1
Author: droonny, 2017-10-26 19:24:38

In fact, both commands output everything correctly. You're just using the wrong browsing tool - the browser. The browser, thinking that the html output successfully eats all repeated whitespace characters (spaces, tabs, transitions to new lines...).

There are many ways to solve this problem:

  1. View output not in the browser (console)
  2. Pass a non-HTMLN Content-Type to the browser. header('Content-Type: text/plain');
  3. Tell the browser not to format the content. Wrap in <pre> tag or set white-space: pre; for the style (css) of the element to output the information to.
  4. Set xdebug. Only on the dev machine!!! It formats the output of the {[4] function very nicely]}
 1
Author: E_p, 2017-10-26 20:40:03