Php brackets and strings
3 answers
If a dollar sign ($) is encountered, the parser will eagerly accept as many tokens as possible in order to form the correct variable name. Name the variable in braces to explicitly indicate the end of the name.
<?php
$beer = 'Heineken';
echo "$beer taste is great"; // works; "'" is an invalid character for variable names
echo "He drank some $beers"; // won't work; 's' is a valid character for variable names but the variable is "$beer"
echo "He drank some ${beer}s"; // works
echo "He drank some {$beer}s"; // works
?>
+8