This article mainly introduces the use of curly braces ' {} ' in PHP, summarizes and analyzes the usage techniques of the braces in PHP in terms of compound statements and variable definitions, in conjunction with the example form, and the need for friends can refer to the following
This example describes the use of curly braces ' {} ' in PHP. Share to everyone for your reference, as follows:
In PHP, curly braces "{}" can play the following role:
1. Combine multiple independent statements into a single compound statement, such as if ... else ... Often used in this way
2, in the variable indirect reference to the delimitation, to avoid ambiguity. For example ${$my _var[8]} and ${$my _var}[8]
3, used to indicate a single character in a string variable (subscript starting from 0), for example
$my _str= "1234"; $my _str{1}= ' 5 '; Now $my _str content is ' 1534 '
This usage is a feature after PHP 5 to eliminate ambiguity caused by the use of brackets.
4. Define the name of the variable
$var = ' sky '; Echo ' {$var}boy ';
<?php$count = 3; echo "Count: $count"; echo "Count: {$count}";//The above two sentences result is the same?>
PHP parses whether the data in double quotes contains a variable (and parses its value), and when double quotes are used, {} is used to define the bounds of the variable.
Like what:
$***= "Man" echo "Iama{$***}youknow"
PHP Parse out $***,
If you don't use PHP, you'll parse $***youknow.
But he doesn't exist.
Output array:
echo "The array element is {$array [element]}."; echo "The array element is {$array->element}"
The above is the whole content of this article, I hope that everyone's study has helped.