The role of PHP curly braces

Source: Internet
Author: User

The role of PHP curly braces

    • When the PHP parser encounters a dollar ($) symbol, he will, like many other parsers, assemble as many tokens as possible to form a valid variable name.

    • You can use curly braces to define the bounds of a variable, to enclose the variable as a whole to parse

    • You can make additions and deletions to the specified characters in the string by {curly braces}

    1. Starting from 0 under string

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

    3. Operation relative to an array

$str = ' ABCD '; echo $str {0}; Output $str subscript 0 A$str{1} = ' Z '; Replace B with subscript 1 as Z, (note: You can only replace one character at a time)

Replacing characters with empty is equivalent to deleting an operation

$str = ' Asdasldjasljfas '; Echo $str {Mt_rand (0,strlen ($STR)-1)}; Randomly take one character mt_rand (0,10)//In the middle of 0-10 randomly take a strlen ($STR)//Calculate the length of this variable

Will often appear in the interview questions.

Related recommendations:

PHP curly braces general rules and explanations

PHP Basic Knowledge Summary (Beginner's Essentials)

PHP basic operator and control structure flow code example

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.