Php syntax, string type? Php syntax: when defining a string, the string must be enclosed by single quotation marks, double quotation marks, or no symbols.
For example:
$ X = 123;
$ Y = "123 ";
$ Z = '000000 ';
Are these three variables the same?
Reply to discussion (solution)
The first one is the same as the last two integers. it is a string type.
However, strings of numbers are sometimes used as numbers in PHP.
For example, $ x = "123 ";
Echo $ x * 3;
Result 369
You can use the getType () function to check the type.
$ X = 123;
This statement assigns the integer to $ x.
$ X = "123"; the value assignment result is the same as that of $ x = '000000 '.
All are granted to the string "123". $ x is of the string type.
For the explanation of single quotes and double quotes, please refer to this post.
Http://bbs.csdn.net/topics/390535456
Without any symbols, how does PHP determine the type of PHP?
$ X = 123;
$ X = abc;
Are they of the same type?
$ X = 123;
No objection. the balanced product is considered as an integer.
Echo gettype ($ x); // integer
Var_dump ($ x); // int (123)
$ X = abc;
Php first checks whether the abc is a constant. if so, it obtains the value of the constant abc.
Otherwise, the system issues a warning Notice>: Use of undefined constant abc-assumed 'ABC'
Then interpreted as a string
Echo gettype ($ x); // string
Var_dump ($ x); // string (3) "abc"
I was very happy to see xu Da using the pinyin input method.
$ X = 123;
No objection. the balanced product is considered as an integer.
Echo gettype ($ x); // integer
Var_dump ($ x); // int (123)
$ X = abc;
Php first checks whether the abc is a constant. if so, it obtains the value of the constant abc.
Otherwise, the system issues a warning Notice>: Use of undefined constant abc-assumed 'ABC'
Then interpreted as a string
Echo gettype ($ x); // string
Var_dump ($ x); // string (3) "abc"
$ X = 123; // automatic type conversion: integer
$ X = abc; // automatic conversion to: string
Right?
I have already made it clear.
I have already made it clear.
However, I don't quite understand it!
If you have to follow the mindset of "non-white or black", you cannot understand it.
The php recognition process is like this.
Is it a number? Is the end of the assignment
Is it a constant? Is the end of the assignment
Use it as a string.
PHP is used to writing character-type single quotes, and variable values are double quotes.
First, you write the source code with text characters. When php analyzes the source code, it will identify the corresponding data format according to the character pattern.
$ X = 123; // 1
$ Y = "123"; // 2
$ Z = '000000'; // 3
For php analysis:
1 is interpreted as a value assignment statement. because there is a = text character, $ x on the left is a variable identifier, and "123" on the right is three consecutive text characters.
When the first text character is a number, the int data format is used to match the subsequent text characters (in short, it is composed of consecutive numbers, and the regular expression is \ d +, if matching is found, the variable is of the int type.
2 similarly, $ y and "" 123 "(two" characters containing continuous text), then the first is detected to be ", beginning with the double quotation mark rule in string data format, use double quotation marks (in simple words, the first is ", The End Is", and there is no "or" in front is \, the regular expression is "([^"] | \ ") +") Matching. it can be found that it is of the string type.
This is the logic for php to identify the source code. it is called a syntax analyzer by academic name. after the syntax analyzer, you will know what type your variables are.
Php is a weak type language, and variables do not need to be declared.
First, you write the source code with text characters. When php analyzes the source code, it will identify the corresponding data format according to the character pattern.
$ X = 123; // 1
$ Y = "123"; // 2
$ Z = '000000'; // 3
For php analysis:
1 is interpreted as a value assignment statement. because there is a = text character, $ x on the left is a variable identifier, and "123" on the right is three consecutive text characters.
When the first text character is a number, the int data format is used to match the subsequent text characters (in short, it is composed of consecutive numbers, and the regular expression is \ d +, if matching is found, the variable is of the int type.
2 similarly, $ y and "" 123 "(two" characters containing continuous text), then the first is detected to be ", beginning with the double quotation mark rule in string data format, use double quotation marks (in simple words, the first is ", The End Is", and there is no "or" in front is \, the regular expression is "([^"] | \ ") +") Matching. it can be found that it is of the string type.
This is the logic for php to identify the source code. it is called a syntax analyzer by academic name. after the syntax analyzer, you will know what type your variables are.
Third, how should we analyze it?
Php syntax requires that a string must be enclosed in double quotation marks or single quotation marks. the content can be numbers, letters, and characters. Right?
For example:
$ X = 'A * 12'; // pair
$ X = "a * 12"; // pair
$ X = a * 12; // syntax error.