PHP in curly braces ' {} ' usage graphic detailed

Source: Internet
Author: User
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.


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.