在php循环中添加img标记

时间:2017-03-24 17:10:53

标签: php loops sass php-5.6

所以这是我的循环。它工作得很好。但是我需要在这个循环之间放置一个图像(在父级别只有一次)并且循环继续

<?php foreach ($nav as $value){
    echo '<li><a href="'.(isset($value->uri) ? $value->uri: '#').'">'.$value->name.'</a>';
    if ($value->children->count() > 0){
        echo '<ul class="white is-dropdown-submenu menu">';
        foreach ($value->children as $child){
            echo '<li><a href="'.(isset($child->uri) ? $child->uri: '#').'">'.$child->name.'</a></li>';
        }
        echo '</ul>';
    }
    echo '</li>';
}; ?>

1 个答案:

答案 0 :(得分:0)

<?php
  $counter = 0; 
  foreach ($nav as $value){
    if($counter === 0) { echo "<img/>"; }
    echo '<li><a href="'.(isset($value->uri) ? $value->uri: '#').'">'.$value->name.'</a>';a
    if ($value->children->count() > 0){
        echo '<ul class="white is-dropdown-submenu menu">';
        foreach ($value->children as $child){
            echo '<li><a href="'.(isset($child->uri) ? $child->uri: '#').'">'.$child->name.'</a></li>';
        }
        echo '</ul>';
    }
    echo '</li>';
    $counter++;
}; ?>