斜杠和''[关闭]之间的差异

Sorry if there is a question that's very similar to this or if there is answer somewhere else but I have a question that's been on my mind lately.

Most people that are versed in programming languages and strings would know that you can escape quotations with a slash (\")

Ex: echo "<input name=\"submit\" type=\"submit\" id=\"brandid\" value=\"submit\" /> ";

But what I usually do is use ' inside of " instead of slashes. So the code above would look something like this:

echo "<input name='submit' type='submit' id='brandid' value='submit' />
";

Could someone explain the differences between the two and the advantages or disadvantages between the two? Sorry if I didn't use the correct terminology or am missing something.

Thanks for any help in advance.

Depends on what you like, and what you need to do. If I've got a lot of variable substitution I need to do, double quotes and curly braces (if needed) are the way to go. I personally don't like adding extra unnecessary markup (read: escaping) if I don't need to.

echo "Hello \"$username\", your last visit was on $lastVisit at $time";

As opposed to...

echo 'Hello "'.$username.'", your last visit was on '.$lastVisit.' at '.$time;

If it's simple HTML markup and no variable substitution is required, then single quotes are fine.

echo '<a href="index.php">Home</a>';

No right answer here.

In your case, the difference isn't much. You can use either of them. This is noticeable for some JavaScript events which need a value to be passed too

echo "<input name='submit' type='submit' onclick='MyAwesomeFunction(\"a string\", \"to be\", \"passed here\");' />
";

Though, I'd prefer the following:

?>
<input name='submit' type='submit' onclick='MyAwesomeFunction("a string", "to be", "passed here");' />
<?php