What does ${ } mean in PHP syntax?
It's an embedded variable, so it knows where to stop looking for the end of the variable identifier.
${username}
in a string means $username
outside of a string. That way, it doesn't think $u
is the variable identifier.
It's useful in cases like the URL that you gave, because then it doesn't need a space after the identifier.
See the php.net section about it.
${ }
(dollar sign curly bracket) is known as Simple syntax.
It provides a way to embed a variable, an array value, or an object property in a string with a minimum of effort.
If a dollar sign ($) is encountered, the parser will greedily take as many tokens as possible to form a valid variable name. Enclose the variable name in curly braces to explicitly specify the end of the name.
<?php $juice = "apple"; echo "He drank some $juice juice.".PHP_EOL; // Invalid. "s" is a valid character for a variable name, but the variable is $juice. echo "He drank some juice made of $juices."; // Valid. Explicitly specify the end of the variable name by enclosing it in braces: echo "He drank some juice made of ${juice}s."; ?>
The above example will output:
He drank some apple juice. He drank some juice made of . He drank some juice made of apples.