Php Learning & amp; Data Type

Source: Internet
Author: User
Apacheweb server software. Similar Products include Microsoft IIS. This function allows a computer to provide the www Service. You can run apache in the following ways. If the address is displayed, the default page indicates that the page is successful. PHP is a server-side language interpretation software. After being loaded by apache, apache adds the function of interpreting PHP files.

Apache web server software. Similar Products include Microsoft IIS. This function allows a computer to provide the www Service. You can run apache in the following ways. The address/display of the default page indicates that the page is successful. PHP is a server-side language interpretation software. After being loaded by apache, apache is added with the function of interpreting php files.

Apache web server software. Similar Products include Microsoft IIS. This function allows a computer to provide the www Service. You can run apache in the following ways.
The address/display of the default page indicates that the page is successful.
PHP is a server-side language interpretation software. After being loaded by apache, apache is added with the function of interpreting php files. This server can run php programs. The access method is as follows:
Address/file name. php
Note: The php file must be in the working directory configured by apache. Not the installation directory.
Mysql small relationshipDataLibrary software. For a variety of softwareDataLibrary support. Saved by the php siteDataMYSQL usually existsDataLibrary. You can also choose otherDataLibrary. Not necessarily MYSQL. It's just that the relationship between MYSQL and PHP is very good ..
Dreamweaver visual webpage editing software. It can be used to compile most of the website script programs. For example, html css asp php. However, it is limited to editing code. Provides visual editing for the visible part. You cannot run dynamic scripts on the server, such as ASP and PHP ..
Note: If you are writing code. All notebooks that come with the system can be written. It is not necessary to use dreamweaver. It is good to compile css html. Writing PHP is no different from writing it in notepad .. You cannot see the effect after running ..
PHP environment: a computer running apache, And the apache has loaded php.DataLibrary is not mandatory software. If you do not needDataLibrary can be left empty. The version number is not important. The new version features a little more. Better security. That's it.

PHP in total 8DataType:

TypeName TypeIndicates Value
Bool Boolean True, false
Integer Integer -2147483647-2147483648
String String type The string length depends on the machine memory.
Float Floating Point Type Maximum 1.8e308
Object Object Instantiate $ obj = new person () through new ();
Array ArrayType $ Arr = array (1, 2, 3, 4, 5, 6); // a one-dimensional array
Resourse
Null Null Value Null

Boolean bool:

For otherTypeWe can use (bool) or (boolean) to forcibly convert eg :( bool) 1 = true;

In the following cases, the default value is false for forced conversion:

Conversion Result
Boolean false var_dump (bool) false) Bool (false)
Integer 0 var_dump (bool) 0 ); Bool (false)
Floating Point 0.0 var_dump (bool) 0.0 ); Bool (false)
String '0' var_dump (bool) '0 '); Bool (false)
Empty array $ arr = array (); var_dump (bool) $ arr) Bool (false)
Empty objects that do not contain any member variables are used only in PHP4, and true in PHP5 Bool (false)
NULL or the variable var_dump (bool) NULL) that has not been assigned a value) Bool (false)
SimpleXML object generated from an XML document without any tags Bool (false)

String '0. 0' is converted to bool (true)

Note:-1 and other non-zero values (both positive and negative) are true.

Integer:

The integer value range is-2147483647--2147483647. If this value is exceeded, it is automatically converted to float type.

We can use echo PHP_INT_SZIE to output the integer length, which is related to the machine. Echo PHP_INT_MAX outputs the maximum integer value

PHP does not perform an integer division operation. If 1/2 is executed, float 0.5 is generated. If you want to perform the integer division, you can use (int) (1/2) = 0 or round (25/7) = 4.

Forcibly convert to integer (int) or (integer) bool type true to 1, false to 0

Float:

Maximum Value: 1.8e308. What is the minimum value? Please advise

The font length of a floating point number is also related to the machine. It seems that there is no PHP_FLOAT_SIZE. Please tell me how to extend it to a floating point number.

StringTypeString:

Four Methods for defining strings:

1. Single quotes

2. Double quotation marks

3. heredoc syntax structure

4. nowdoc syntax structure (after PHP5.3.0)

Single quotes

The single quotation mark defines the original string, and all content in it is processed by the string. If the string contains single quotation marks, it can be escaped \.

Double quotation marks

Strings defined by double quotation marks will parse some special characters (\ n, \ B) and variables

You can place variables in double quotation marks instead of converting them into strings ):

$ Num = 10;

$ Str = "$ num"; // $ str is 10 of the string type

Heredoc syntax structure

< <标示符< strong>

String itself

Identifier

The identifier at the end must be at the beginning of a line, and the Definition Format of the identifier must follow the rules defined by PHP. It can only contain numbers, letters, and underscores, and cannot start with a number underline.

If a line of the ending identifier does not contain any other character, you can add a semicolon after the identifier, and there cannot be tabs or spaces before and after the semicolon; otherwise, PHP will not be able to parse the identifier, the identifier will be searched down. If it is not found before the end of the file, an error will be generated.

Heredoc is a double quotation mark without double quotation marks. It can contain double quotation marks without escaping and can parse special characters and variables.

Nowdoc syntax structure

<'Identifier'

String itself

Identifier

The START identifier of nowdoc must be enclosed in single quotes. The end identifier and other rules are the same as those of heredoc.

Nowdoc is a single quotes without single quotes. The strings contained in nowdoc are output as they are, and the special characters and variables contained in nowdoc are not parsed.

If double quotation marks contain several situations in array variables

//First, we define the following Array

[Php]View plaincopyprint?

  1. $ Arr = array (
  2. 'One' => array (
  3. 'Name' => 'jiangtongg ',
  4. 'Sex' => 'male'
  5. ),
  6. 'Two' => 'zhaohaitao ',
  7. 'Three '=> 'fanchangfa'
  8. );



The first element in the array is two-dimensional, and the last two are one-dimensional. When we access one-dimensional, the following methods are provided:

[Php]View plaincopyprint?

  1. Echo "$ arr [two]" // The key has no single quotation marks.
  2. Echo "$ arr ['two']" // an error occurs when the key has single quotes. If we change it to echo "{$ arr ['two']}", the result can be output correctly.
  3. Echo "{$ arr [two]}" // There are double braces, but the key does not have single quotes. In this case, PHP will first find whether the constant banana exists. If yes, it will be replaced, an error occurred because no two constant exists.

It can be seen that when accessing a one-dimensional array, either the key is not enclosed by quotation marks (considering the third case). If it is added, it will be included.

Multi-dimensional array Test

[Php]View plaincopyprint?

  1. Echo "$ arr [one] [name]"; // The output result is Array [name]. It can be seen that it returns an Array and only resolves one dimension.
  2. Echo "{$ arr ['one'] ['name']}"; // The output result is jiangtong.

The braces key must be enclosed in double quotation marks for multi-dimensional array access.

ArrayType
In the stringTypeAs mentioned in, if it is legal to enclose it in braces without the key quotation marks, PHP will first find whether it is a constant named as the key and replace it if it exists, if not, a warning will be generated that the constant cannot be found before it is processed as a normal string. Therefore, we recommend that you add single quotation marks.

To convert to an array, use (array) type or array (type). However, if only one value is converted to an array, an array of elements is obtained and the subscript is 0, convert NULL to an array to obtain an empty array.

We can change the value of the array when traversing the array. You can use the reference implementation above PHP5.0.

[Php]View plaincopyprint?

  1. $ Arr = array ('A', 'B', 'C', 'D', 'E ');
  2. Foreach ($ arr as & $ value)
  3. {
  4. $ Value = strtoupper ($ value );
  5. Echo $ value;
  6. } // Output result ABCDE



ObjectType

To instantiate an object, we use new to add a person class. We can use the following method:

[Php]View plaincopyprint?

  1. $ ObjPerson = new person ();


Forced conversion (object): if an object is converted to an object, it does not change. For any other value, an object of stdclass will be instantiated. If this value is NULL, an empty object will be instantiated. If the array is converted into an object, the key of the array will be used as the object's attribute, value is the attribute value, and otherTypeThe member variable named scalar contains this value.

[Php]View plaincopyprint?

  1. $ Arr = array ('one' => 'A', 'two' => 'B ');
  2. $ Obj = (object) $ arr;
  3. Echo $ obj-> one // The output result is;

Note: This is an array composed of keys. If there is no character key array, I don't know how to access it. I want to tell my younger brother. Thank you.

For other values

[Php]View plaincopyprint?

  1. $ Obj1 = (object) 'jiang ';
  2. Echo $ obj1-> scalar; // output result jiang



NULLType

Null is case insensitive and NULLTypeOnly one value indicates that one variable has no value. In the following three cases, the variable is considered NULL.

1. The value is NULL.

2. Not assigned

3. unset ();

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.