PHP source code

Source: Internet
Author: User
Ec (2); 1. boolean value: false (0, blank, null); & nbsp; true (-1, non-0 value ); 2. The echo $ s output content is $ s; & nbsp; If & quot; contains $ s or {$ s}, then the value of the variable will be displayed. {$ S} is recommended. & Nbsp; Use & quot; script ec (2); script




1. boolean value: false (0, blank, null); true (-1, non-0 );

2. The echo ''$ s' output is $ s;
If "" contains $ s or {$ s}, the value of the variable is displayed. {$ S} is recommended.
When "" is used, if "" is used in "", it must be used for escape, for example, echo "" sss "";

3. String connection: use punctuation "." To connect strings.

4. Access characters in a string: Use curly brackets after the string to specify the offset of the expected character from scratch.
The strlen ($ str) function can obtain the string length.
$ Str [0] gets the first character of the string $ str.
Substr ('000000', 5, 1) gets a character starting with 123456 characters and the result is "6 ".

5. strval ($ s) converts the $ s value to a string, and intval ($ s) converts the $ s value to an int integer value.
Double quotation marks: "a" B "= a" B;

6. array: (array brackets, comma, =>)
Array sorting: sort ($ arr );
Definition: $ arr = array (1 => ''11'', ''foo'' => ''fffooo '', ''info'' => array (2 => 22, ''ghost'' => ''host ''));
Reference: $ arr [1] $ arr [''foo''] $ arr [''info''] [2] $ arr [''info''] [''ghost' ']
Count ($ arr) gets the number of array elements
Traverse the array: $ arr = array (1 => '000000', 2 => '000000', 3 => '000000 '');
Foreach ($ arr as $ k => $ v)
Echo "{$ k }_{ $ v}
"; // Output: 2017111 2_222 3_333

7. Object

Class foo
{
Var $ a = 's'; // class variable !!

Function init () // class function
{
Echo "Doing foo .";
Echo $ this-> a; // reference the class variable !!
}
}

$ Bar = new foo;
$ Bar-> init ();
?>


8. Variables

Isset ($ s) checks whether the variable has been set. If it is not set yet, referencing $ s will cause the php prompt: Undefined variable.

By default, values assigned between variables do not affect each other (Value assignment mode );
In the case of $ a = "a"; $ B = & $ a, the values of any variable in $ a and $ B are changed, the value of another variable also changes (Transfer address assignment mode ).

Pre-Defined variables of PHP5:
$ _ SERVER ["REMOTE_ADDR & quo

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.