PHP在带有花括号的字符串中嵌入数组元素

I would like to know what the advantage of using curly braces is in the following context:

$world["foo"] = "Foo World!";
echo "Hello, {$world["foo"]}.
";

is over the following:

$world["foo"] = "Foo World!";
echo "Hello, $world["foo"].
";

In particular, how is it that the braces resolve any possible ambiguity in this case (or similar cases)?

See the other answers for the "echo" explanation, but if you're using heredoc, such as the following:

echo <<<EOHTML
<td>{$entity['name']}</td>
EOHTML;

You need the curly braces to properly use the associative array.

Second example will not be parsed. So first is better:)

Anyway, I prefer to use

echo "Hello" . $world["foo"] . ".
";

Because it is more easy to read to me.

Besides, there is another way:

$world["foo"] = "Foo World!";
echo "Hello, $world[foo].
";

There no resaons to use one or another. you what you(or your team) like.