PHP braces '{}' usage example summary, php zhongda
This example describes the use of braces '{}' in PHP. We will share this with you for your reference. The details are as follows:
In PHP, braces "{}" can play the following role:
1. Merge multiple independent statements into a composite statement, for example, if... else...
2. Define variables in indirect references to avoid ambiguity. For example, the distinction between $ {$ my_var [8]} and $ {$ my_var} [8]
3. Used to indicate a single character in a string variable (the subscript starts from 0). For example:
$ My_str = "1234"; $ my_str {1} = '5'; // The content of $ my_str is '123'
This feature is used after PHP 5 to eliminate ambiguity caused by brackets.
4. Define the variable name
$ Var = 'sky'; echo "{$ var} boy ";
<? Php $ count = 3; echo "Count: $ count"; echo "Count: {$ count}"; // the above two statements have the same results?>
PHP analyzes whether the data in double quotation marks contains a variable (and parses its value). When double quotation marks are used, {} is used to define the variable boundary.
For example:
$ *** = "Man" echo "Iama {$ ***} youknow"
PHP parses $ ***,
If php is not used, $ *** youknow will be parsed.
He does not exist.
Output array:
Echo "The array element is {$ array [element]}."; echo "The array element is {$ array-> element }"