Related explanations about PHP 5 data types

jacklove
Release: 2023-03-25 14:46:01
Original
1571 people have browsed it

Data type is the most basic knowledge point in PHP. This article will provide a detailed understanding of the relevant knowledge of data types.

String(String), Integer(integer type), Float(Floating point type), Boolean(Boolean type), Array (array), Object (object), NULL (null value).

PHP String

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

You can put any text in single and double quotes:

Example

<?php $x = "Hello world!";echo $x;echo "<br>"; 
$x = &#39;Hello world!&#39;;echo $x;?>
Copy after login

PHP Integer

An integer is a number without decimals .

Integer rules:

The integer must have at least one digit (0-9)

The integer cannot contain commas or spaces

Integers have no decimal point

The integer can be a positive or negative number

The integer can be specified in three formats: decimal, hexadecimal (prefixed by 0x) or octal (prefixed by 0).

In the following examples we will test different numbers.

PHP var_dump() function returns the data type and value of the variable:

Example

<?php $x = 5985;var_dump($x);echo "<br>"; 
$x = -345; // 负数 var_dump($x);echo "<br>"; 
$x = 0x8C; // 十六进制数var_dump($x);echo "<br>";$x = 047; // 八进制数var_dump($x);?>
Copy after login

PHP floating point type

Floating point numbers have decimal parts Number, or exponential form.

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

Example

<?php $x = 10.365;var_dump($x);echo "<br>"; 
$x = 2.4e3;var_dump($x);echo "<br>"; 
$x = 8E-5;var_dump($x);?>
Copy after login

PHP Boolean type

The Boolean type can be TRUE or FALSE.

$x=true;
$y=false;
Copy after login

Boolean type is usually used for conditional judgment. You will learn more about conditional control in the following chapters.

PHP Array

Arrays can store multiple values ​​in one variable.

In the following example, an array is created, and then the PHP var_dump() function is used to return the data type and value of the array:

Example

<?php $cars=array("Volvo","BMW","Toyota");var_dump($cars);?>
Copy after login

In the following chapters You will learn more about arrays.

PHP Object

The object data type can also be used to store data.

In PHP, objects must be declared.

First, you must declare a 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:

Example

In the above example, the PHP keyword this points to the current object A pointer to an instance that does not point to any other object or class.

You will learn more about objects in the following chapters.

PHP NULL value

The NULL value indicates that the variable has no value. NULL is a value of data type NULL.

The NULL value indicates whether a variable has a null value. It can also be used to distinguish between data null values ​​and NULL values.

You can clear the variable data by setting the variable value to NULL:

Example

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

This article introduces the data types in detail. For more learning materials, please pay attention to php Chinese You can watch it online.

Related recommendations:

Demo about AJAX voting

Understanding and using PHP Cookie related knowledge

PHP MySQL operations and methods of reading data

The above is the detailed content of Related explanations about PHP 5 data types. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template