Beginner's view: Dynamic Web page making technology PHP variable type

Source: Internet
Author: User
Tags array integer variables range

PHP's variable type is not many, there are the following five kinds:

String
Integer
Double
Array
Object

Strings are string variables, either single or thousands of-character strings that use this variable type. It is worth noting that to assign a string to a string variable, precede it with double quotes (for example, "This is a string"). When you want the string to be changed, you can use the overflow character, which is the backslash plus the specified symbol, if \x plus two digits, such as \xfe, table 16, see the following table:

\ double quotation mark \ backslash \ n line break \ r send out cr\t (tab) symbolic meaning

Integer is an integral type. In a 32-bit operating system, it has a valid range of 2,147,483,648 to +2,147,483,647. To use a 16-bit integer, you can add 0x to the surface.

Double is the floating-point number type. In a 32-bit operating system, its effective range is 1.7e-308 to 1.7e+308.

Array is an array variable, which can be two-dimensional, three-dimensional, or multidimensional, where the elements are also free, can be string, Integer, or double, or even array.

object is a class variable, currently in PHP, the class is not much, if the class, Microsoft's ASP class is still more than the default class of PHP, I believe this depends on the efforts of everyone. But then again, the Web CGI program requires efficiency, in a completely object-oriented way, and I'm afraid the user will be impatient when browsing because the program is slow to execute.

To use a variable, just add a dollar number to the front of the English string, and the variable name is still not available in Chinese. As for the case of variables is not the same, for the development of PHP program team, it is best to use the same variable style, lest then because of the size of the variable problem, spend a lot of unnecessary time to find the problem point, then trouble.

The following are examples of the use of variables:

$mystring = "I am a string";
$wilsonpeng = "Web Teaching network is really good";
$newline = "line changed \ n";
$int 1 = 38;
$int 2 = 49;
$hexint = 0x10;
$float 1 = 1.732;
$float 2 = 1.4e+2;
$myarray 1 = Array ("Zi", "ugly", "Yin", "Mao");
$myarray 2 = Array (
"Branches" => Array ("Zi", "ugly", "Yin", "Mao"),
"Zodiac" => Array ("Rat", "ox", "Tiger", "Rabbit"),
"Digital" => Array (1, 2, 3, 4)
);

Class is more cumbersome to use, you have to define a category, and you must first have a method before you can use the class, as in the following example:

class Foo {
function Do_foo () {
echo "doing foo.";
}
}
$bar = new Foo;
$bar-> Do_foo ();

In addition, there are Boolean values (Boolean), usually 1 is true,0 to false.

Between variables, if you want to convert a type, you're free in a PHP program, and you use it directly, without having to go through a special conversion function. Of course, it's a bit far-fetched to turn floating-point numbers into integers, but it's nice to be able to turn floating-point numbers into strings.



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.