回显foreach循环的$值时出现意外结果

I've written the following code:

$hierachy = new hierachy;
$iterator = $hierachy->singlePathroot($name1);

try {
    print_r($iterator);

    foreach($iterator as $key=>$value) {
        echo $value;
        echo $value['0'];
    }
}

The result of the print_r is…

Array ( [0] => Array ( [name] => Fruit ) [1] => Array ( [name] => Red ) )

…but below that, the echo statements produce ArrayArray.

How can I echo the same values I see in the print_r output?

You can echo like this:

echo $iterator [0]['name'];
echo $iterator [1]['name'];

And in your loop:

$hierachy = new hierachy;
$iterator = $hierachy->singlePathroot($name1);
try {
   print_r($iterator);
   foreach($iterator as $key=>$value)
   {
       echo $value['name'];
   }
} catch (Exception $e) { }

try below

echo $value['name'];