PHP Quick Start Learning-4 (data type)

Source: Internet
Author: User

PHP 5Data Type

String (String), Integer (integer), float (floating-point), Boolean (Boolean), Array (array), Object (objects), null (null value).

PHP string

A string is a sequence of characters, just like "Hello world!".

You can put any text in single and double quotation marks:

<?  $x = "Hello world!" ; Echo $x ; Echo "<br>"$x = ' Hello world! ' ; Echo $x ;? >
PHP Integral type

An integer is a number that has no decimals.

Integer rule:

    • Integers must have at least one number (0-9)
    • Integers cannot contain commas or spaces
    • Integers are no decimal points.
    • Integers can be positive or negative
    • Integer types can be specified in three formats: decimal, hexadecimal (prefixed with 0x), or octal (prefixed with 0).

In the following example we will test for different numbers. The PHP var_dump () function returns the data type and value of the variable:

<?PHP$x= 5985;Var_dump($x);Echo"<br>"; $x=-345;//Negative numberVar_dump($x);Echo"<br>"; $x= 0x8c;//Hexadecimal numberVar_dump($x);Echo"<br>";$x= 047;//octal numberVar_dump($x);?>

PHP floating Point type

A float is a number with a decimal point, or an exponential form.

In the following example we will test for different numbers. The PHP var_dump () function returns the data type and value of the variable

<?  $x = 10.365; Var_dump ($x); Echo "<br>"$x = 2.4e3; Var_dump ($x); Echo "<br>"$x = 8E-5; Var_dump ($x);? >

PHP Boolean type

The Boolean type can be TRUE or FALSE.

$x=true; $y=false;

Boolean is commonly used for conditional judgment, more tutorials on conditional control.

PHP arrays

An array can store multiple values in a variable.

An array is created in the following instance, and then the data type and value of the array are returned using the PHP Var_dump () function:

<?  $cars=array("Volvo", "BMW", "Toyota"); Var_dump ($cars);? >

PHP Object

Object data types can also be used to store data.

In PHP, the object must be declared.

First, you must declare the class object using the Class keyword. A class is a structure that can contain properties and methods.

Then we define the data type in the class and then use the data type in the instantiated class:

<? PHP class car{  var$color;   function Car ($color= "Green") {    $this$color;  }   function What_color () {    return$this,color;  }}? >

The PHP keyword in the above example is a pointer to the current object instance and does not point to any other object or class.

PHP NULL Value

A NULL value indicates that the variable has no value. Null is a value with a data type of NULL.

A null value indicates whether a variable is a null value. It can also be used to distinguish between null values and data nulls.

Variable data can be emptied by setting the value of the variable to NULL:

<? PHP $x= "Hello world!" ; $x=null; Var_dump ($x);? >

PHP Quick Start Learning-4 (data type)

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.