I’m a total PHP newb, so there is probably a better way of outputting a row’s class based on different variables.
Is this bad, and if it is why is it?
if ($variable1 > 0 && $variable2 != 2) {
echo "<tr class='variable1'>";
}
elseif ($variable2==2)
{
echo "<tr class='variable2'>";
}
else {
echo "<tr>";
}
I would write it like this:
notice that on the equality test I use the constant before the variable.. this is a habit so that if I miss one equal it would result in an error that I would be forced to correct it instead of a “strange” behavior
another thing is that I give the initial value to $class_name and that will be the default one
also I use apostrophes instead of quotation marks because it is faster (because the way you did it php will parse the string for variables)
and the last thing is that I echo multiple string.. that’s also faster than concatenating 3 strings (
and not echo
)