How can I display double quotes inside a single-quoted string in PHP?

Solution:

The issue here is escaping. In PHP, if you want to include a double quote ” inside a double-quoted string, you must escape it with a backslash \.

Example:


echo "\""; 
// Output: "

Without escaping:


echo "foo"bar"; 
// Syntax error! The string is terminated at the first unescaped quote

With escaping:


echo "foo\"bar"; 
// Output: foo"bar

Applying it to your code

Original (causes syntax issues):


echo "stores[".$row['BarID']."] = [". $row['BarName'] . ", " . $row['Address'] . ...

Corrected (escape quotes for string literals):


echo "stores[".$row['BarID']."] = [\"". $row['BarName'] . "\", \"" . $row['Address'] . "\"]";

✅ Key points:

\” tells PHP to treat the quote as a literal character, not as the end of the string.

Always escape quotes when they appear inside a string delimited by the same type of quote.