What are the knowledge points of PHP variables?
This article mainly introduces what are the PHP variable knowledge points, have a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
1. Declaration and assignment of variables
Declaring a PHP variable must be represented by a dollar sign "$" followed by a variable name, and then use "=" to assign a value to the variable. As follows:
The characteristics of variables in 2.PHP
You have to start with $. For example, the variable an is to be written as $a, which is not a part of the variable name.
The first letter of a variable cannot start with a number. The variable name must begin with a letter or an underscore.
The names of variables are case-sensitive.
Variables do not use special symbols, Chinese, _ (underscore) is not a special symbol
Variable naming should be meaningful (variable name such as xxx,aaa,ccc)
The correct naming is as follows:
3.echo display variable instruction
Echo is a command commonly used in PHP to output and display functions. You can use it to display any visible character, for example:
PHP comment
Annotation has many functions: marking the key points, easy to find, easy to forget for a long time, and improving work efficiency.
/ /, # # means one-line comments, usually used more.
/ * Multiline comments * / indicates multiline comments
Examples are as follows:
/ * here is smoking harmful to health * / 4.PHP variable data type
4.1 Integer
Integers are integers, which can be positive or negative.
4.2 Boolean type
Boolean has only two values: true (true) / false (false)
4.3 string
A string is a continuous sequence of characters. In PHP, there are three ways to define a string:
Declare in single quotation marks
Declare in double quotation marks
Declare with a character delimiter
Where the character delimiter is used when you need to enter a very large string.
Note when declaring with character delimiters:
Write three less than signs after the equal sign of the variable
If the double quotation marks are replaced by single quotation marks, the output result is: $a Chinese net, not.
Insert a variable in double quotation marks. If there are English or Chinese characters after the variable, it will concatenate the character with the variable and treat it as a whole variable.
Adding special characters after the variable can solve the problem:
Or instead of realistic special symbols, you can wrap variables in curly braces:
Double quotation marks and single quotation marks can be inserted into each other:
4.4 floating point type
Floating point is the decimal in mathematics. Valid values range from 1.8E-308 to 1.8E+308. Floating-point numbers are more accurate than integer data types.
Thank you for reading this article carefully. I hope the article "what are the knowledge points of PHP variables" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!