Should I use $row['variable'] or $row["variable"]?

I’ve seen both the single and double quote used with $row, but is there one correct syntax?

Thank you!

It doesn’t matter. I’d use single quotes if I had something like an echo and I didn’t wanna escape the double quotes…

Likewise, if I echo’d using single quotes I’d use double quotes inside the $row variable.

Just depends.

I use single quotes if the value is constant and need no further evaluation.

I would go with single quotes because the cannot be interpreted.

For example, in this sample PHP would treat what is in the double quotes as a variable…

echo "Your Order Total is: $order_total"

In your case, my example doesn’t really apply, but following that style, I use single quotes when something should be treated as literal. And your case, your database row reference is literal.

At least that is how I see it.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.