Learn PHP Records "II"

Source: Internet
Author: User
Tags learn php

1. Floating point number

<? PHP $a = 1.234$b = 1.2e3$c = 7E-10;? >

$c should be a power?

This is the power of the format.
Exponent_dnum [+]? ({lnum} | {Dnum}) [EE] [+-]? {Lnum})


Other types (not including string) if you want to convert to float, first convert to an integer
Then do not compare the floating point number, this is very strange and normal, because this floating point may be rounded or other form, you do not know his true value to, floating point

2: String !

http://segmentfault.com/q/1010000000310292/a-1020000000310320

This just means that the string type of PHP is array of bytes.

PHP can use Unicode as normal. My experience is:

    • The php script file itself uses the UTF-8 character set.
    • The Web page uses UTF-8 encoding.
    • The MySQL database uses the UTF8 character set.
    • Various string operations use the multibyte string series function.

That is, string is made up of a char byte

Transfer \ and ' is in front of them plus \

But like \ r \ n is the expression of their own

Here comes the point! The difference between single and double quotes, I was depressed for a long time!

The escape sequences of variables and special characters in single-quote strings will not be replaced.

<?PHPEcho' This was a simple string ';//multiple lines can be enteredEcho‘You can also has embedded newlines in strings The This is the IT isokay to do‘;//output: Arnold once said: "I ll be back"Echo' Arnold once said: ' I\ ' ll be back ';//output: You deleted c:\*.*?Echo' You deleted c:\\*.*? ';//output: You deleted c:\*.*?Echo' You deleted c:\*.*? ';//output: This would not expand: \ n A newlineEcho' This'll not expand: \ n A newline ';//output: Variables do not $expand $eitherEcho' Variables does not $expand $either ';?>

The explanation is clear, I see a lot more eyes.

The most important feature of a string defined in double quotation marks is that the variable is parsed


There are two ways to do this, one is called simple rules and the other is complex rules.

A simple rule is to nest a variable directly.

<? PHP $juice = "Apple"; Echo $juice Juice. " Php_eol ; // Invalid. "S" is a valid character for a variable name, and the variable is $juice. Echo $juices. " ;? >// output results He drank some apple juice. .

It's not because he's complicated, but because he can express more complex semantics. Give an example

Echo "This works too: {$obj->values[3]->name}";

Valid, when using multiple arrays in a string, be sure to enclose it in parentheses.
echo "This works: {$arr [' foo '][3]}";

Then there are heredoc and newdoc that correspond to double quotes and single quotes, respectively:

The form is:

<? PHP $a = <<<eodhahaha EOD; $b = <<< ' EOT 'hahhahaeot; The difference between them is that EOD and no quotes. The Newdoc is EOT with quotes and it is possible to initialize the static variables and then the variables in the EOT will not be parsed.

Rest, and see again in the afternoon.




Learn PHP Records "II"

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.