Use of Brackets
This question already has an answer here:
This is pretty simple actually. Inside a string context, like when wrapped in quotes, when you need to parse an object attribute like a method or property you wrap it inside curly braces.
So this can help explain the statement: print "Author: {$product->getProduct()};
Now second example is just an extension of the first one, where the author has used multiple lines and round brackets for readability. It can be also written as:
$b = "{$this->title}";
$b .= "({$this->producerMainName},{$this->producerFirstName})";
$b .= ": page count - {$this->nPages}";
Here supposing we had following values:
$this->title = "Author Details ";
$this->producerMainName = "Doe";
$this->producerFirstName = "John";
$this->nPages = 10;
Then if we had echoed $b
after the assignments above we would get:
Author Details (Doe,John): page count - 10
上一篇: 为什么$ {0x0}是正确的?
下一篇: 使用括号