Question: Here is The My Array Code...

```
$data = array(
            'data_1',
            'data_2',
            'data_3',
            'data_4',
            'data_5' => array(
                            'data_5_1',
                            'data_5_2'
                        )
);

```

i Want to Ountput Like The : -

```
data_1
data_2
data_3
data_4
data_5
    data_5_1
    data_5_2

```

Here is My Code I try to Self But I Show Error

```
foreach($data as $da){ 
     echo $da."<br>";
}

```

Error Found Like This 

```
data_1
data_2
data_3
data_4
Notice: Array to string conversion in filename.php on line 3
Array

```

Please Fix this problem & Use echo not print\_r

Answer: 
You could use iterators:

```
foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($data)) as $item)
  echo "$item<br>", PHP_EOL;

```

As asked in comments, if you want either the key or value depending on type, you can use the flag `SELF_FIRST` and the ternary operator:

```
foreach(new RecursiveIteratorIterator(new RecursiveArrayIterator($data), RecursiveIteratorIterator::SELF_FIRST) as $key => $item)
  echo (is_scalar($item) ? $item : $key) . '<br>', PHP_EOL;

```
```
foreach ($data as $val) {
    if(is_array($val)){
        foreach ($val as $row) {
            echo "<br>&nbsp;&nbsp;&nbsp;&nbsp;".$row;
        }
    }
    else{ 
         echo "<br>".$val;
    }
}

```