Home > Article > Backend Development > Summary of usage of "{}" braces in PHP
This article mainly introduces a summary of the usage of "{}" braces in PHP. It has certain reference value. Now I share it with you. Friends in need can refer to it.
In PHP, Braces "{}" can play the following roles:
1. Combine multiple independent statements into a compound statement, such as if...else...which is often used
2. Delimit the variable indirect reference to avoid ambiguity. For example, the difference between ${$my_var[8]} and ${$my_var}[8]
3. Used to indicate a single character in a string variable (the subscript starts from 0), such as
$my_str="1234"; $my_str{1}='5'; //现在 $my_str 内容为 '1534'
This usage is a feature after PHP 5, used to eliminate ambiguities caused by the use of square brackets.
4. Define the name of the variable
$var='sky'; echo "{$var}boy";
Related recommendations:
Usage analysis of bind_param() function in php
How to implement string flipping in php
The above is the detailed content of Summary of usage of "{}" braces in PHP. For more information, please follow other related articles on the PHP Chinese website!