"> -6ren">
gpt4 book ai didi

php - 简单的 PHP 问题 : Conditional CSS class based on user

转载 作者:行者123 更新时间:2023-11-28 10:57:38 26 4
gpt4 key购买 nike

如果评论是由管理员做出的,我正在使用此代码为评论框显示不同的样式类

<li class="<?php if ($comment->user_id == 1) $oddcomment = "authorstyle"; echo $oddcomment; ?>"></li>

管理员的 user_id = 1。现在,如果我想添加 user_id 5 和 6,我该如何编辑这段代码?

最佳答案

您可以使用 ||运算符(表示或):

if ($comment->user_id == 1 || $comment->user_id == 5 || $comment->user_id == 6)

或者你可以使用 in_array:

if (in_array($comment->user_id, array(1, 5, 6))

它看起来更好,更易于维护。 :)

关于php - 简单的 PHP 问题 : Conditional CSS class based on user,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4677346/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com