在foreach圈附近的背景图象

时间:2016-07-14 19:49:22

标签: php foreach

我有这个PHP代码:

echo '<div class="inventorySimple"> 
        <div class="list">'; 
foreach ($r['result']['achievements']['0']['achievements'] as $item) { 
    echo '<li class="liste" data-tag=', $item['description'], '> 
            <div class="achiev-title">   ', $item['title'], '</div> 
            <div class="description">      ', $item['description'], '</div> 
            <div class="bg-image">';  
    if(!empty($item['criteria'])){ 
        foreach ($item['criteria'] as $item2){             
            echo '<li>', $item2['description'], ' </li>'; 
        } 
    }  
} 

echo '</div></ul></ul>'; 

?>  

我需要第二个foreach循环结果背后的背景图片。我试图设置:

<div class="bg-image">';

循环,但背景图像不在结果后面。

我的代码的HTML结果:

<div class="achiev-title">   Tolles Trio</div>
<div class="description">      Erreicht mit drei verschiedenen Klassen die Höchststufe.</div>

<div class="bg-image"></div></li><li>
Druide </li><li>
Mönch </li><li class="liste" data-tag="Erreicht" mit="" fünf="" verschiedenen="" klassen="" die="" höchststufe.="">

正如您所看到的,<div class="bg-image"></div>不在foreach输出周围。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

尝试将数据标记附近的行更改为:

 data-tag="', $item['description'], '"> 

并清理那个

hochststufe.="" 

hochststufe="">

此外,您可能更容易以这样的方式编写PHP servlet:

<?php

// Current manner     
$someVal = "something";
echo ' some html ' , $someVal , ' 
    some more html '; 


// Another way to write the values, without relying on 
// similar puncutation marks and arbitrary spacing.

$someArray = array("blip", "blap");
$index = 0;

$htmlOutput = "";
$htmlOutput .= "\n\t\t<some html commands with attribute=\" ";
$htmlOutput .= $someArray[$index++];
$htmlOutput .= " \" another attribute=\"blah\" ></some> ";

$htmlOutput .= "\n\t\t<some html commands with attribute=\" ";
$htmlOutput .= $someArray[$index];
$htmlOutput .= " \" another attribute=\"blah\" ></some> ";

echo $htmlOutput;

?> 

这使源输出产生差异,如:

<body>
 some html something some more html 
        <some html commands with attribute=" blip " another attribute="blah" ></some> 
        <some html commands with attribute=" blap " another attribute="blah" ></some>  
</body>