PHP foreach 循环(输出到 CSS)
是否有一个管理区域,用户可以在其中选择类别名称和与之匹配的关联颜色。有 10 个选项(即 10 个类别,10 个颜色),
然后将其输出到标题以控制类别颜色:
例如,
$cat1 = get_option('catname1');
$col1 = get_option('col1');
$cat2 = get_option('catname2');
$col2 = get_option('col2');
依此类推,直到 10。然后将这些输出到 CSS,如下所示(如果用户在管理面板):
if($cat1){echo "
.".$cat1"{ color:".$col1." !important; }
.".$cat1." { background-color:".$col1." !important; }" };
我如何将这些语句组合到 foreach 中(基本上是从 cat1 到 cat10)?
If have an admin area where users can select a category name and an associated color to match it. There are 10 options (i.e. 10 categories, 10 colors)
This then gets outputted to the header to control category colors:
So for example,
$cat1 = get_option('catname1');
$col1 = get_option('col1');
$cat2 = get_option('catname2');
$col2 = get_option('col2');
and so on until 10. These are then outputted to CSS as follows (if the user has inputted anything on the admin panel):
if($cat1){echo "
.".$cat1"{ color:".$col1." !important; }
.".$cat1." { background-color:".$col1." !important; }" };
How would I combine these statements in a foreach (basically to go from cat1 to cat10)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用
for
循环:You can use a
for
loop: