Home  >  Article  >  Backend Development  >  The role of PHP curly braces

The role of PHP curly braces

韦小宝
韦小宝Original
2017-11-14 13:09:142087browse

The role of PHP curly braces

  • When the PHP parser encounters a dollar ($) symbol, he Like many other parsers, it will combine as many identifiers as possible to form a legal variable name.

  • You can use curly braces to clarify the boundaries of variables and enclose the variables as a whole for parsing

  • You can use {curly brackets} to add, delete, modify, and query specified characters in the string

  1. characters The string starts from 0

  2. You can use [square brackets] to achieve the same operation

  3. Operation relative to an array

$str = 'abcd';
echo $str{0}; //输出$str中下标为0的
a$str{1} = 'z'; //将下标为1的b替换成z,(注意:一次只能替换一个字符)

Replacing the characters with empty characters is equivalent to the delete operation

$str = 'asdasldjasljfas';
echo $str{mt_rand(0,strlen($str)-1)}; //随机取一个字符
mt_rand(0,10) //在0-10中间随机取一个
strlen($str) //计算这个变量的长度

in the interview

that often appears in the question Related recommendations:

##detailed explanation of common rules for php curly braces

Summary of PHP basic knowledge (necessary for novices)

PHP basic operators and controls Structure process code example

The above is the detailed content of The role of PHP curly braces. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:What is object-orientedNext article:What is object-oriented