我目前在尝试解耦这个foreach数组时遇到了一些麻烦。它基本上将所有复选框打印为表格中的组(小部件)。
<?php foreach ($widgets as $id => $widget): ?>
<label for="<?php print $widget->id; ?>">
<?php print $widget->label; ?>
</label>
<?php print $widget->id; ?>
在$ widgets上执行print_r函数会显示ff:array:
Array
(
[filter-tid] => stdClass Object
(
[widget] =>
Option 1
Option 2
Option 3
[operator] =>
[label] => label here
[id] => edit-id-here
)
[filter-tid_1] => stdClass Object
(
[widget] =>
Option 1
Option 2
Option 3
[operator] =>
[label] => label here
[id] => edit-id-here
)
....... and so on....
我如何分别打印foreach中的每个项目?感谢。
答案 0 :(得分:0)
您可以嵌套foreach
并循环$widget->widget
<?php foreach ($widgets as $id => $widget): ?>
<?php foreach ($widget->widget as $option): ?>