-2

我将如何出去显示这些信息,以便颜色代码正确显示文本?这只是一个小片段,但我似乎无法让它工作。我试图使它成为一个数组但被卡住了。

if($pclass == "c1" or "c2" or "c3" or "c4" or "c5"){
  $pcolor = '<font color="#0000FF">';
  $pend = '</font>';
} else {
  if($pclass == "w1" or "w2" or "w3" or "w4" or "w5"){
    $pcolor = "<font color='#FF6600'>";
    $pend = "</font>";
  } else {
    if($pclass == "r1" or "r2" or "r3" or "r4" or "r5"){
      $pcolor = "<font color='#00FF00'>";
      $pend = "</font>";
    } else {
      if($pclass == "h1" or "h2" or "h3" or "h4" or "h5"){
        $pcolor = "<font color='#CC00CC'>";
        $pend = "</font>";
      }
    }
?>
<div id="top">
<h1>
  <?php echo "$requestname"; ?>
</h1>
<p class="small">
<?php 
echo "$player's primary class is $pcolor $pclass $pend";
echo ", $player's secondary class is $sclass";
4

1 回答 1

0

or当您应该使用 PHP 的运算符时,您正在使用它||。此外,您在底部缺少两个括号,无论如何这可能会弄乱您的整个脚本。最后,您需要检查每个值的条件,而不仅仅是第一个值。

<?php

if ($pclass == "c1" || $pclass == "c2" || $pclass == "c3" || $pclass == "c4" || $pclass == "c5") {
    $pcolor = '<font color="#0000FF">';
    $pend   = '</font>';
} else {
    if ($pclass == "w1" || $pclass == "w2" || $pclass == "w3" || $pclass == "w4" || $pclass == "w5") {
        $pcolor = "<font color='#FF6600'>";
        $pend   = "</font>";
    } else {
        if ($pclass == "r1" || $pclass ==  "r2" || $pclass ==  "r3" || $pclass == "r4" || "r5") {
            $pcolor = "<font color='#00FF00'>";
            $pend   = "</font>";
        } else {
            if ($pclass == "h1" || $pclass == "h2" || $pclass == "h3" || $pclass ==  "h4" || $pclass == "h5") {
                $pcolor = "<font color='#CC00CC'>";
                $pend   = "</font>";
            }
        }
    }
}
?>
于 2013-04-28T21:11:54.470 回答