Beginners: Dynamic web page creation tips: PHP variable types

Source: Internet
Author: User
Tring is a string variable. it applies to single characters or strings of thousands of characters. It is worth noting that you must specify a string to a string variable and add double quotation marks (for example, 'This is a String') at the beginning and end of the variable '). When you want to change the character string for a row, you can apply the overflow character, that is, adding the specified symbol to the backslash. if it is \ x, add two digits. for example, \ xfe indicates the hexadecimal character of the table.

Php has few variable types, including the following five types:

String
Integer
Double
Array
Object

String is a string variable. this variable type is applied to a single character or a string of thousands of characters. It is worth noting that you must specify a string to a string variable and add double quotation marks (for example, 'This is a String') at the beginning and end of the variable '). When you want to change the line of a string, you can apply the overflow character, that is, adding the specified symbol to the backslash. If \ x is followed by two digits, for example, \ xfe is the hexadecimal character of the table. See the following table:

\ 'Double quotation marks \ backslash \ n line feed \ r send the cr \ t hop (tab) symbol meaning

Integer is an integer type. In a 32-bit control system, its effective scope is-2,147,483,648 to 2,147,483,647. To apply a 16-digit integer, you can add 0x to the plane.

Double is a floating point type. In a 32-bit control system, its effective scope is 1.7e-308 to 1.7e 308.

Array is an array variable. it can be a two-dimensional, three-dimensional, or ** array. the elements in the array are also very free. they can be string, integer, double, or even array.

Object is a class variable. Currently, there are few classes in php. if we talk about classes, microsoft's asp classes are still more than php's default classes. trust depends on everyone's efforts. But again, the web cgi program requests efficiency. using a complete object-oriented method, I am afraid users will be impatient during browsing because of slow program performance.

To apply a variable, you only need to add a dollar sign $ Before the English string. Currently, the variable name cannot apply Chinese characters. As for the case sensitivity of variables, for the team that develops php programs, it is best to apply the same variable application style to avoid the variable size title at that time, it is troublesome to spend a lot of unnecessary time searching for titles.

The following are examples of variable application:

$ Mystring = 'I am string ';
$ Wilsonpeng = 'webpage tutorial network is really good ';
$ Newline = 'newline \ n ';
$ Int1 = 38;
$ Int2 = 49;
$ Hexint = 0x10;
$ Float1 = 1.732;
$ Float2 = 1.4e 2;
$ Myarray1 = array ('sub', 'Ugly ', 'yin', 'Mao ');
$ Myarray2 = array (
'Geographic support '=> array ('sub', 'Ugly', 'yin ', 'Mao '),
'Zodiac '=> array ('Rat', 'ox ', 'Tiger', 'rabbit '),
'Number' => array (1, 2, 3, 4)
);

The application of the class is more troublesome. you must first define the category, or even use methods to apply the class, as shown in the following example:

Class foo {
Function do_foo (){
Echo 'doing foo .';
}
}
$ Bar = new foo;
$ Bar-> do_foo ();

In addition, there is a boolean value (boolean). generally, 1 is true, and 0 is false.

To convert the type between variables, it is very free in the php program and can be used directly without special conversion functions. Of course, it is far-fetched to convert a floating point to an integer. However, it is also very beneficial to convert a floating point to a string.

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.