我有以下数据:
Item 1 Title: Lorem ipsum dolor sit amet Language: Deutsch Item 2 Title: Lorem ipsum dolor sit amet Language: Deutsch Item 3 Title: Lorem ipsum dolor sit amet Language: Englisch Item 4 Title: Lorem ipsum dolor sit amet Language: Franzoesisch
我希望只有“Deutsch”项目显示在案例中(“dev.domain.de”),“Englisch”项目显示在案例中(“dev.domain.com”)等等
<?php
$strRendersettings = ($this->settings)? 'settings' : 'view';
?>
<?php
if (count($this->data)):
?>
<ul>
<?php
switch($_SERVER['HTTP_HOST'])
{
case ("dev.domain.de"):
if ($arrItem['text']['new_docs_auswahl'] == "Deutsch"){
foreach ($this->data as $arrItem): ?>
<li class="new_doc_home"><a href="" ><strong><?php echo $arrItem['text']['new_docs_titel']; ?>:</strong><br>
<p><?php echo $arrItem['text']['new_docs_Text']; ?></p></a>
<?php echo $arrItem['text']['new_docs_auswahl']; ?>
</li>
<?php
endforeach;
}
break;
case ("dev.domain.com"):
foreach ($this->data as $arrItem): ?>
<li class="new_doc_home"><a href="" ><strong><?php echo $arrItem['text']['new_docs_titel']; ?>:</strong><br>
<p><?php echo $arrItem['text']['new_docs_Text']; ?></p></a>
<?php echo $arrItem['text']['new_docs_auswahl']; ?>
</li>
<?php
endforeach;
break;
case ("dev.domain.fr"):
foreach ($this->data as $arrItem): ?>
<li class="new_doc_home"><a href="" ><strong><?php echo $arrItem['text']['new_docs_titel']; ?>:</strong><br>
<p><?php echo $arrItem['text']['new_docs_Text']; ?></p></a>
<?php echo $arrItem['text']['new_docs_auswahl']; ?>
</li>
<?php
endforeach;
break;
}
?>
</ul>
<?php else: ?>
<?php endif; ?>
答案 0 :(得分:0)
这个伪代码可以是:
switch(host)
{
case "de":
select german data;
break;
case "fr":
select french data;
break;
case "en":
default:
select english data;
break;
}
foreach data as item
display list element with item
end
答案 1 :(得分:0)
第一种情况下如果和 foreach 的顺序是错误的。请参阅固定和优化的变体:
<?php $strRendersettings = ($this->settings)? 'settings' : 'view'; ?>
<?php if (count($this->data)): ?>
<ul>
<?php
$match = "";
switch($_SERVER['HTTP_HOST'])
{
case "dev.domain.de":
$match = "Deutsch";
break;
case "dev.domain.com":
$match = "Englisch";
break;
case "dev.domain.fr":
$match = "Franzoesisch";
break;
}
foreach ($this->data as $arrItem) {
if ($arrItem['text']['new_docs_auswahl'] == $match){
?>
<li class="new_doc_home"><a href="" ><strong><?=$arrItem['text']['new_docs_titel']?>:</strong><br></a>
<p><a href="" ><?=$arrItem['text']['new_docs_Text']?></a></p>
<?=$arrItem['text']['new_docs_auswahl']?>
</li>
<?
}
}
?>
</ul>
<?php endif; ?>
并且请检查W3C有关标记嵌套顺序的信息。