div 类中的 PHP 变量

标签 php html css variables if-statement

我只想知道是否可以做这样的事情:

<?php
   if(condition1 > condition2){
       $variable = "class1";
   }else{
       $variable = "class2";
   }
?>
<div class=$variable></div>

谢谢。

最佳答案

是的,你可以像这样使用它

    <?php
      if(condition1 > condition2){
      $variable = "class1";
      }else{
      $variable = "class2";
      }
     ?>

    <div class="<?php echo $variable; ?>" ></div>

关于div 类中的 PHP 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24162047/

相关文章:

php - 使用 htaccess 使 url 不区分大小写

php - 根据用户时区安排在 24 小时之前发送电子邮件

$output 中的 php echo

javascript - jQuery 垂直 slider 保持滑动

javascript - jQuery:在模糊时隐藏上下文菜单

javascript - Owl Carousel 幻灯片全部显示为一张幻灯片

php - 如何在 CLI 中运行 laravel 程序?

javascript - Angularjs ui-view 不工作

javascript - 从外部样式表(从文件)读取样式属性

html - 背景固定元素