About PHP 5 data types

Source: Internet
Author: User
Data types are the most basic knowledge points in PHP, and this article will learn more about data types.

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:

Instance

<?php $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:

Instance

<?php $x = 5985;var_dump ($x); echo "<br>"; $x =-345; Negative var_dump ($x); echo "<br>"; $x = 0x8c; Hexadecimal number var_dump ($x); echo "<br>"; $x = 047; Octal number Var_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:

Instance

<?php $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 judgments. You'll learn more about conditional control in the next sections.

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:

Instance

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

You'll learn more about arrays in the next sections.

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:

Instance

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.

You will learn more about objects in the next chapters.

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:

Instance

<?php$x= "Hello world!"; $x =null;var_dump ($x);? >

This article introduces in detail the data type, the more study material clear concerns the PHP Chinese network to be able to watch.

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.