From PHP Manual [1]-basic knowledge

Source: Internet
Author: User
Tianya has recently used its free time to read the manual completely, and has published some things that we think are easy to ignore in the blog. Not to mention, article 1.

Tianya has recently used its free time to read the manual completely, and has published some things that we think are easy to ignore in the blog. Not to mention, article 1.

Note: for line breaks, although the actual meaning of line breaks in HTML is not very great, the proper use of line breaks can make HTML code easy to read and beautiful. Will PHP automatically delete its Terminator when outputting it?> The next line feed. This function is designed to embed multi-segment PHP code in a page or include a PHP file without substantial output. at the same time, it also raises some questions. If the PHP Terminator?> After the output, you can add a space after the line feed, or add a line feed to the last echo/print statement.

Note: The End mark of the PHP code segment at the end of the file can be omitted. in some cases, it is better to omit include () or require, in this way, unexpected white spaces will not appear at the end of the file, and the response header can still be output later. It is also convenient to use the output buffer, so you will not see unexpected white spaces generated by the contained files.

Note: Unlike the other two syntaxes, variables and escape sequences in single quotes strings are not replaced by variable values.
[Tianya note] that the variables in single quotes are not parsed and output as strings.

The characters in a string can be accessed and modified by specifying the offset from scratch with curly braces after the string.

 
 
  1. $ Str = 'Hello World! ';
  2. Echo $ str {1}; // output e
  3. ?>

Note: The unset () function allows you to cancel the key name in an array. Note that the array will not rebuild the index.

Always put quotation marks on the array index represented by a string. For example, use $ foo ['bar'] instead of $ foo [bar]. But why is $ foo [bar] wrong? You may have seen the following syntax in the old script:

 
 
  1. $foo[bar] = 'enemy';
  2. echo $foo[bar];
  3. ?>

This is wrong, but it can run normally. So why is it wrong? The reason is that this code has an undefined constant (bar) instead of a string ('bar'-note quotation marks), and PHP may define this constant later, unfortunately, your code has the same name. It can run because PHP automatically converts a bare string (a string without quotation marks and does not conform to any known symbol) into a normal string whose value is the bare string. For example, if no constant is defined as bar, PHP replaces it with 'bar' and uses it.
Note: Once again, it is legal to leave no quotation marks on the index in the double quotation mark string, so "$ foo [bar]" is legal.

The following mandatory conversions are allowed:

 
 
  1. (Int), (integer)-convert to integer
  2. (Bool), (boolean)-convert to boolean
  3. (Float), (double), (real)-convert to floating point type
  4. (String)-convert to string
  5. (Array)-convert to an array
  6. (Object)-convert to object

Note that empty spaces and tabs are allowed in parentheses.

Note: HTML forms do not pass integers, floating-point numbers, or Boolean values. they only pass strings. To check whether a string is a number, use the is_numeric () function.
Note: When $ x is not defined, usage of such variables as if ($ x) may cause an E_NOTICE-level error. Therefore, you can use empty () or isset () functions to initialize variables.

Note: Even! Higher than =, PHP still allows expressions similar to the following: if (! $ A = foo (). In this example, the output of foo () is assigned to $.

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.