PHP basic syntax and basic data structure (i)

Source: Internet
Author: User
 
  


An assignment statement; the "Var_dump" function can display the data type of our variables.
In the variable, because the variable occupies a different space unit, but also divided into several data types, like the supermarket packaging bags, there are several different types of goods, different products use a variety of packaging bags. We can get the memory consumed by the current PHP by using "Memory_get_usage".
In PHP, 8 primitive types are supported, including four scalar types, two composite types, and two special types. PHP is a loosely-typed language that does not have to declare the variable's data type to PHP, and PHP automatically converts the variable into an automatic data type, which reduces the threshold of learning PHP to a certain extent. If you touch the C language or the Java language, you will notice that you need to declare the variable's data type when declaring the variable.
The use of Boolean variables in PHP is important to note that when we use the "echo" command to Output a Boolean type, if "true" then the output is "1", "false" will not output anything. We can use the "var_dump" function to get its true data type. Like what:

 
  


Although the "echo" command output is 1, "Var_dump" shows us the identity "$flag" as a Boolean type.
What do we do when you include quotes in your string? There are three types of options:
First scenario: Double quotation marks are embedded in single quotation marks;
The second scenario: embedding single quotation marks in double quotation marks;
The third scenario: Use the escape character "\".
When a variable name is included in the output statement:
When a variable is enclosed in double quotes, the variable is concatenated with the contents of the double quotation mark;
When a variable is included in a single quotation mark, the variable is exported as a string.
Such as:

 
  


The output is:
Cenzi,i Love you!
Cenzi, $love
What happens when my string is long?
We can use the HEREDOC structure to solve the problem, first using the delimiter to represent the string, then providing an identifier after God, then the string, and finally the end string with the identifier provided. Where the representation can be defined by itself, it must be consistent. The end identifier must be a different line, and this line except "GOD", and with ";" After the end, can not have any other characters, before and after cannot have, including spaces, otherwise there will be an error.
First special type-resources
Resources (Resource): resources are created and used by specialized functions, such as open files, data connections, and graphical canvases. We can manipulate resources (create, use, and release). Any resources should be released in a timely manner when they are not needed. If we forget to release the resources, the system automatically enables the garbage collection mechanism to reclaim the resources after the page has been executed to avoid the memory being exhausted. Suppose you found a file on the server and wanted to see what was written in it. PHP can do it!. Assuming a file on the server is "F.txt", we need to use the special data type of the resource. The following test assumes that you have a file ("/data/webroot/resource/php/f.txt") under the path. Note: F.txt text files must be set to UTF-8 format when saving, to avoid garbled characters.

 
  

Second special type-null type

Null (NULL): null is a null type, is insensitive to case, the null type has only one value, indicating that a variable has no value, when it is assigned null, or has not been assigned, or is unset () (logoff definition), in three cases the variable is considered NULL.

The above describes the basic PHP syntax and basic data structure (a), including the content of the text, I hope that the PHP tutorial interested in a friend helpful.

  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.