: This article mainly introduces the basic syntax and basic data structure of php (1). If you are interested in the PHP Tutorial, refer to it.
Value assignment statement; the "var_dump" function can display the data type of our variables.
In variables, because the space units occupied by variables are different, they are also divided into several data types, just like the packaging bags of supermarket products, there are several different types, different products use different packaging bags. We can use "memory_get_usage" to obtain the memory consumed by PHP.
In PHP, eight primitive types are supported, including four scalar types, two composite types, and two special types. PHP is a loose language that does not need to declare the data type of a variable to PHP. PHP automatically converts the variable to an automatic data type, which lowers the threshold for learning PHP to a certain extent. If you have been familiar with the C or JAVA language, you will find that you need to declare the data type of the variable when declaring the variable.
When using the Boolean variable in php, note that when we use the "echo" command to output the Boolean type, if it is "true", the output is "1 ", "false" means nothing is output. We can use the "var_dump" function to obtain its real data type. For example:
Although the output result using the "echo" command is 1, "var_dump" shows us that "$ flag" is a Boolean identity.
What should we do when your string contains quotation marks? There are three solutions:
Solution 1: Insert double quotation marks into single quotes;
Solution 2: insert single quotation marks into double quotation marks;
Solution 3: Use the escape character "\".
When the output statement contains a variable name:
When double quotation marks contain variables, the variables are connected with the content in double quotation marks;
When a single quotation mark contains a variable, the variable is output as a string.
For example:
Output:
Cenzi, I love you!
Cenzi, $ love
What should I do if my string is long?
We can use the Heredoc structure to solve this problem. First, use the delimiters to represent the string, then provide an identifier GOD, then the string, and finally end the string with the provided identifier. The identifier can be defined by yourself, but must be consistent. The end identifier must start with another line. besides "GOD", this line ends with ";". it cannot contain any other characters, including spaces, otherwise, an error occurs.
First Special type-resource
Resource: resources are created and used by dedicated functions, such as opening files, connecting data, and drawing canvases. You can create, use, and release resources ). Any resources should be released in time when they are not needed. If we forget to release the resources, the system will automatically enable the garbage collection mechanism to recycle the resources after the page is executed to avoid memory consumption. Suppose you find a file on the server and want to see what it says. PHP can do this !. Assume that the server has a file named "cmdf.txt". In this case, we need to use the Special Data type such as resource. The premise for the following tests is that you have files in the ("/data/webroot/resource/php/f.txt") path. Note: f.txt text files must be saved in UTF-8 format to avoid garbled characters.
Type 2-null
NULL (NULL): NULL is a NULL type and is case insensitive. The NULL type has only one value, indicating that a variable has no value. if it is assigned NULL or has not been assigned a value, or unset () (deregister definition). in these three cases, the variable is considered NULL.
The above introduces the basic syntax and basic data structure of php (1), including some content, and hope to help those who are interested in PHP tutorials.