Farflame Farflame - 1 year ago 58
PHP Question

How can I add two values to a class attribute?

I'm trying to add two classes to a

by echoing them out. All of them contain one class every time, but the other class can change. I hop into the function which just has all of the classes in an array as follows...

$StandClassArray = array('north stand', 'east stand', 'south stand', 'west stand');

Note that these SHOULD be two separate classes, one is called 'stand' and one is called 'north' or 'south' etc. So all
's need the 'stand' class and one of the 4 compass points.

When I add this to my
with the following....

$Side = 0 ; // This would have been passed to the function usually.
echo "<td class = $StandClassArray[$Side]>Text</td>";

What I get in the browser is ...

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

I've tried doing it other ways, such as ...

echo "<td class = $StandClassArray[$Side] stand>Text</td>"; // Just the compass point in the array for this.

But it gives the same result.

I'm pretty sure that I've had this problem before, ages ago, but can't remember how to fix it.

Answer Source

Why not just echo the value:

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

Another approach may be (following your logic):

echo "<td class ='".$StandClassArray[$Side]."'>Text</td>";
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download