Как перебрать вложенный массив? ⇐ Php

Кемеровские программисты php общаются здесь
Anonymous
Как перебрать вложенный массив?

Сообщение Anonymous »

Мне нужно напечатать приведенную ниже структуру массива как:

Node Title 1

topic 1

topic 2

topic 3

topic 4

asset title1

asset title2

asset title3


Как я могу использовать foreach - PHP

Что я сделал:

foreach($output['fields'] as $key => $value) {
if($key == 'title') {
echo $value;
}
if(count($value['main_topic'])) {
foreach($value['main_topic'] AS $mainkey => $main_topic) {
echo $main_topic['topic_title'];
}
}
}


Приведенный выше синтаксис печатает заголовок. Но не массив main_topic.


Array
(
[fields] => Array
(
[nid] => 136
[node_title] => Node title 1
[node_type] => curriculum
[title] => Node title 1
[main_topic] => Array
(
[0] => Array
(
[row_id] => 136
[topic_id] => 411847
[weight] => 10
[topic_title] => topic 1
)

[1] => Array
(
[row_id] => 136
[topic_id] => 411839
[weight] => 2
[topic_title] => topic 2
)

[2] => Array
(
[row_id] => 136
[topic_id] => 411840
[weight] => 3
[topic_title] => topic 3
)

[3] => Array
(
[row_id] => 136
[topic_id] => 411841
[weight] => 4
[topic_title] => topic 4
[subfield] => Array
(
[1] => Array
(
[asset_title] => asset title 1
)

[2] => Array
(
[asset_title] => asset title 2
)

[3] => Array
(
[asset_title] => asset title 3
)

)

)

)

)

)


Подробнее здесь: https://stackoverflow.com/questions/919 ... sted-array

Вернуться в «Php»