doutui6644
2013-04-01 22:22 阅读 35
已采纳

分开foreach项目并单独打印

I'm currently having some trouble trying to decouple this foreach array. It basically prints all checkboxes as a group (widget) in a form.

<?php foreach ($widgets as $id => $widget): ?>  
 <label for="<?php print $widget->id; ?>">
      <?php print $widget->label; ?>
 </label>
      <?php print $widget->id; ?>

Doing print_r function on $widgets shows the 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.... 

How would I go about printing each item in the foreach separately? Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    doupin5408 doupin5408 2013-04-01 22:28

    You can just nest the foreach and loop over $widget->widget

    <?php foreach ($widgets as $id => $widget): ?>
        <?php foreach ($widget->widget as $option): ?>
    
    点赞 评论 复制链接分享

相关推荐