PHP output variable enlarge bracket {} function

Source: Internet
Author: User
Tags strlen

PHP output Variable Enlargement bracket, what is this writing? Look at the following code:

The code is as follows Copy Code

<?php

Header ("content-type:text/html; Charset=utf-8 ");

$test = "1 variable 1";

echo "preceded by a String AA". $test. "BB Back string";

echo "preceded by a string AA {$test} bb back string";

?>

You can see that the PHP output variable increases the parentheses with the. Operator output variable string effect is the same, summed up the following 3 points to help understand the PHP output variable enlarge the function of bracket {}:

1. The expression {} inside is a variable, the execution is processed according to the variable;

2. Refer to the special inclusion of variables used in strings so that you can reduce the amount of code input by not using the. operator.

3. Prevent the variable name from being linked with the following string.

Report:

The function of the curly braces {} In a string variable:

PHP variable followed by a brace {}, which is filled with numbers, refers to the PHP variable corresponding ordinal number of characters.

For example:

The code is as follows

$str = ' Hello ';
echo $str {0}; Output is H
echo $str {1}; Output to E

If you want to check how long a string satisfies, consider replacing the strlen function with this brace {} plus isset, because isset is a language structure and strlen is a function, so using isset is more efficient than using strlen.

For example, to determine whether a string is less than 5 length:

The code is as follows

if (!isset ($str {5})) is better than if (strlen ($STR) < 5).

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.