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 do you include the field name?
==================================================
Best Answer
The meaning of the PHP variable placed in curly braces
- //The following is okay as it ' s inside a string. Constants is not
- //looked for within strings so no E_notice error here
- print "Hello $arr [fruit]"; //Hello Apple
-
- //With one exception, braces surrounding arrays within strings
- //allows constants to being looked for
- Print "Hello {$arr [fruit]}"; //Hello carrot
- Print "Hello {$arr [' Fruit ']}"; //Hello Apple
Here are some explanations for why:
- Represents a variable inside {}, which is handled by variable when executed
- Refer to the special inclusion of variables in a string, so that you can reduce the amount of code input by not using the. operator.
In fact, the output of the block is equivalent to print "Hello". $arr [' fruit '];
PHP: The role of curly braces (curly braces {}) in string variables
The PHP variable is appended with a curly brace {}, which is filled with numbers, which refers to the character of the corresponding ordinal of the PHP variable.
For example:
$str = ' Hello ';
echo $str {0}; Output is H
echo $str {1}; Output to E
If you want to check how much length a string satisfies, consider replacing the strlen function with this curly brace (curly brace) and isset, because Isset is a language structure and strlen is a function, so using isset is more efficient than using strlen.
For example, determine whether a string is less than 5 in length:
if (!isset ($str {5})) is better than if (strlen ($STR) < 5).
PHP variable Under what circumstances braces {}