Foreach跳过选项值

时间:2017-04-21 20:14:43

标签: php foreach

我试图找出如何从循环中删除语言ID 10.

 <? foreach ($languages as $langId => $langDetails): ?>
            <option value="<?=$langId?>" <?=($langId == zbanRegistry::getInstance()->lang) ? 'selected="selected"' : NULL;?>><?=$langDetails['LABEL']?></option>            
            <? endforeach; ?>

结果是:

<select name="lang" id="lang" >
    <option value="1" selected="selected">Language 1</option>           
    <option value="2" >Language 2</option>          
    <option value="3" >Language 3</option>          
    <option value="4" >Language 4</option>          
    <option value="5" >Language 5</option>          
    <option value="6" >Language 6</option>          
    <option value="7" >Language 7</option>          
    <option value="8" >Language 8</option>          
    <option value="9" >Language 9</option>          
    <option value="10" >Language 10</option>                    
</select>

感谢任何帮助: - )

1 个答案:

答案 0 :(得分:0)

您可以检查langId的值。也许是这样的?

<? foreach ($languages as $langId => $langDetails): ?>
    <? if ($langId != 10): ?>
        <option value="<?=$langId?>" <?=($langId == zbanRegistry::getInstance()->lang) ? 'selected="selected"' : NULL;?>><?=$langDetails['LABEL']?></option>            
    <? endif; ?>
<? endforeach; ?>