What is the difference between single-quoted and double-quoted strings in PHP?
What is the difference between single-quoted and double-quoted strings in PHP?
The main differences between single-quoted and double-quoted strings in PHP are:
$name = "John";
echo "Hello, $name!"; // Output: Hello, John!
echo 'Hello, $name!'; // Output: Hello, $name!
\n
for newline, while single-quoted strings treat escape sequences literally[1][2][3]. For example:echo "Hello\nWorld"; // Output:
//Hello
//World
echo 'Hello\nWorld'; // Output: Hello\nWorld
Performance: Single-quoted strings are slightly faster than double-quoted strings because PHP doesn't need to parse variables and escape sequences within them[1][2]. However, this difference is negligible in most cases.
Escaping quotes: To include a single quote ...
junior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào