简体   繁体   English

为INI文件中的每个部分复制PHP代码

[英]Replicate PHP code for each section in an INI file

<? $config = parse_ini_file('/list.ini', true); ?>
<?echo'<select id="LBox" name="listbox" size="20" style="display:none;">';
    foreach($config[MPR] as $id=>$label){
        switch ($id)
        {
        case ($id==select):
        echo'<option value="0" selected="selected"></option>';
        break;
        case ($id>0 && $id<=10):
        echo'<optgroup label="'.$label.'">';
        break;
        case ($id>10 && $id<=20):
        echo'</optgroup>';
        break;
        default:
        echo'<option value="'.$id.'">'.$label.'</option>';
        }
    }
echo'</select>';?>

Above is code that builds a hidden list box and fills its options from an INI file. 上面的代码构建一个隐藏的列表框,并从INI文件中填充其选项。 I would Like to replicate this for each section in my ini, but I am unsure of the best way to do this, other than copy and paste this 8 times with a new $config[x] value. 我想为ini的每个部分复制此内容,但是我不确定执行此操作的最佳方法,除了使用新的$ config [x]值复制并粘贴8次之外。 Is there a way to replicate this for each section? 有没有一种方法可以复制每个部分?

编写一个执行该操作并接受任何更改的函数(例如$ config [x])作为参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM