One, no matter what the program, function name () {}, for () {}, .... Too much, do not say also know what to do with.
Two, $str {4} After the string's variable followed by {} braces and brackets are all treating a string variable as an array.
Three, {$val} at this time the curly braces function is to tell PHP, surrounded by as a variable processing.
Copy Code code as follows:
$arr =array (0=>123, ' name ' => ' Hello ');
foreach ($array as $k => $v) {
echo "SELECT * from Blog_blogs where blog_tags like '%{$arr [$k]}% ' ORDER by blog_id '; Plus a brace is just a marker that will be a variable
}
Echo ' <br/><br/><br/><br/><br/><br/><br/> ';
foreach ($array as $k => $v) {
echo "SELECT * from Blog_blogs where blog_tags like '%{{$arr [$k]}}% ' ORDER by blog_id '; With two curly braces, the outer part will be a normal character.
}
Use curly braces to differentiate variables
echo "$arr [' name ']"; Use this sentence to report grammatical errors
Echo ' {$arr [' name ']} '; This sentence is normal, the characters in curly braces are treated as variables
$STR {4} follows the variable of the string with the {} brace and the bracket as the array processing of a string variable
$str = ' ABCDEFG ';
echo $str {4};
{} The role of curly braces in PHP (the meaning of PHP variables inside curly braces)
such as: $sql = "INSERT into article (' channel_id ', ' title ', ' Detail ', ' pub_time ') values (' {$cid} ', ' {$title} ', ' {$detail} ', ' {$ Time} ');
What does it mean to add {}?
And why should I include a field name?
==============================================
At least it is easy to read ~ ~ ~ "is the insert into the statement required, because the string to appear in pairs
Add {} Sometimes to prevent the variable name from being linked to the string that follows
For example
{$cid}DD
If CID=AA
So {$cid}dd=aadd
If you do not add, you look at the $ciddd, not become a CIDDD variable ~ ~
PHP variable followed by a brace {}, which is filled with numbers, refers to the PHP variable corresponding ordinal number of characters.
For example:
$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 curly brace (curly brace) 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:
if (!isset ($str {5})) is better than if (strlen ($STR) < 5).
The following explanations that explain why:
Represents {} is a variable that, when executed, handles the special inclusion of referencing variables in a string, so that you can reduce the amount of code input by using the. operator.
In fact, the output is equivalent to print "Hello". $arr [' fruit '];
One, using the curly braces of the variable
As mentioned in the previous log, PHP notice warns the following sentence:
Switch (${action}. ' _ '. ${child}) {
There is no problem at first sight. I also queried the definition of variables in the PHP manual: here.
1, variable variables of the situation
As you can see, in the case of a variable using curly braces, as with most data, the variable variable (Variable variables). It refers to:
Reference
In the order of variable variables with arrays, you are have to resolve a ambiguity problem. It, if you write $ $a [1] then the parser needs to know if your meant to $a [1] as a variable, or if you wanted $ $a a s the variable and then the [1] index from that variable. The syntax for resolving this ambiguity are: ${$a [1]} for the "a" and ${$a}[1] for the second.
That is, in order to be able to use variable variables in an array environment, it is necessary to use braces {} to limit the range of variables according to different circumstances. The ${$a [1]} is completely different from the ${$a}[1]:
Reference
${$a [1]} here $a[1] is a variable;
${$a}[1] Here $a is a variable;
2, delimitation, avoid ambiguity
In fact, this situation is similar to the variable variable. For example, if you use the "." connectors, connecting a string, which may be the case:
echo $str. ' _2010 ';
It may be simpler to write with curly braces:
echo "${str}_2010";
Visible, if there is no curly braces, it is possible to treat the whole $str_2010 as a variable. Of course, such a way of writing can only be used in double quotes, inside the single quotation marks will not carry out variable substitution.
3, a single character in a string variable
For example:
Copy Code code as follows:
<?php
$str = ' 000 ';
$str {0}= ' 1];
Echo $str; Output is 100
?>
This is not hard to understand, and is consistent with the effect of brackets [], somewhat like the case of a string as an object in Python. Therefore, the following statements function the same:
Copy Code code as follows:
<?php
$str = ' 000 ';
$str [0]= ' 1];
Echo $str; Also output 100
?>
However, these are not what I want to explain, really want to describe the situation, please see below.
The similarities and differences of the use of curly braces in variables
First, turn the error message output of PHP all on, that is,/etc/php.ini:
Reference
error_reporting = E_all
Display_errors = On
Then, open the test page, where the code is:
Copy Code code as follows:
<?php
$test = ' 123 ';
Echo $test;
echo "${test}";
echo "{$test}";
Echo ${test}. ' _';
Echo ${test};
?>
You will see the following results:
Reference
123123123
Notice:use of undefined constant test-assumed ' test ' in/var/www/html/phpcrm/testpages/variables.php on line 6
123_
Notice:use of undefined constant test-assumed ' test ' in/var/www/html/phpcrm/testpages/variables.php on line 7
123
What does that mean?
1. Acceptable wording
From the output, "123123123" indicates that the echo statements in the preceding three lines are normal:
Copy Code code as follows:
Echo $test;
echo "${test}";
echo "{$test}";
2, do not recommend the wording
The next two lines have the notice warning that the test variable was treated as a constant and only later assumed to be a variable. Therefore, in order to avoid ambiguity and conflict, it is not recommended to write this:
Copy Code code as follows:
Echo ${test}. ' _';
Echo ${test};
However, there can be a flexible way of writing
Copy Code code as follows:
echo ${' Test '}. ' _';
echo ${' Test '};
It's not going to be an error if you write that.
3. Incorrect wording
A lot of information on the Internet, ${var} and {$var} 's role is the same. However, if you add another sentence:
echo {$test};
Then you will get the following error message:
Reference
Parse error:syntax Error, unexpected ' {' in/var/www/html/phpcrm/testpages/variables.php on line 8
This is not a notice warning, is an error, because parsing problems, the program will not function correctly.
Third, summary
In conjunction with the previous two sections, I believe that when you use curly braces for variable references, you should follow these guidelines:
Reference
1. The correct writing is: ${var};
2, with double quotes together;
3, according to the meaning of the need to express delimitation.
So, finally, I change the switch line to:
Switch ("${action}_${child}") {
The notice warning is no longer present.