Php 如何向类属性添加两个值?

Php 如何向类属性添加两个值?,php,class,echo,Php,Class,Echo,我试图通过回显将两个类添加到td。它们每次都包含一个类,但另一个类可以更改。我跳转到一个函数中,该函数只包含数组中的所有类,如下所示 $StandClassArray = array('north stand', 'east stand', 'south stand', 'west stand'); 请注意,这应该是两个独立的类别,一个称为“stand”,另一个称为“north”或“south”等。因此所有td都需要“stand”类别和4个罗盘点中的一个 当我将其添加到我的td时,请使用以下内

我试图通过回显将两个类添加到
td
。它们每次都包含一个类,但另一个类可以更改。我跳转到一个函数中,该函数只包含数组中的所有类,如下所示

$StandClassArray = array('north stand', 'east stand', 'south stand', 'west stand');
请注意,这应该是两个独立的类别,一个称为“stand”,另一个称为“north”或“south”等。因此所有
td
都需要“stand”类别和4个罗盘点中的一个

当我将其添加到我的
td
时,请使用以下内容

$Side = 0 ; // This would have been passed to the function usually.
echo "<td class = $StandClassArray[$Side]>Text</td>";
$Side=0;//这通常会传递给函数。
呼应“文本”;
我在浏览器中得到的是

<td class = "north" stand = "">Text</td>
文本
我试过其他方法,比如

echo "<td class = $StandClassArray[$Side] stand>Text</td>"; // Just the compass point in the array for this.
回显“文本”;//只是阵列中的指南针点。
但它给出了同样的结果


我很确定我在很久以前就遇到过这个问题,但不记得如何解决它。

为什么不重复这个值:

<td class="<?php echo $StandClassArray[$Side] ?>">Text</td>

浏览器的实际输出为:

<td class = north stand>Text</td>
文本
这不是有效的标记。浏览器正在尽力为您更正它。只需对输出进行明确说明,将引号包含在您希望包含它们的位置:

echo "<td class = \"$StandClassArray[$Side]\">Text</td>";
回显“文本”;
应输出:

<td class = "north stand">Text</td>
文本

您需要将html属性的值用引号括起来,尤其是当该值包含空格时。啊,我明白了,我的最终输出中没有引号。修正了,谢谢。谢谢,我现在明白了,最后一个字符串中根本没有引号。Doh。
<td class = "north stand">Text</td>