Summary of seven data types of PHP

Time:2021-9-14

To get started with PHP, you must first learn to build an environment, and then learn basic syntax. The foundation of PHP includes data types, operators, variables and constants.

In this article, we mainly understand what data types are. Data type refers to a general term of the same kind of data, which is generally described as XX data type.

For example, if integers and decimals are numbers, we will collectively call them digital data types. In PHP, data types are divided into seven categories:

PHP has seven data types. Seven types:

  1. character string,
  2. Integer,
  3. float,
  4. Boole,
  5. Array,
  6. Object,
  7. resources.

Examples of data types for PHP are as follows:

<?php 

/*String:

A string of characters enclosed in single or double quotation marks*/

echo "12rqwr#@%";

echo 'rq#@wr12%';

/*Integer:

It refers to an integer. It cannot have a decimal point. It can be positive or negative*/

echo 3124;

echo -3124;

/*Float:

An integer or decimal with a decimal point, and an exponent*/

echo 0.35;

echo 3.0;

/*Boolean:

Refers to yes or no, represented by true and false*/

echo True;

echo False;

/*Array:

Refers to a set of data, including string, integer, floating point, etc*/

print_r(array('hello',124,'world',0.15));

/*Object:

Contains the structure of properties and methods. See the object section for details*/

class ClassName extends AnotherClass

{

 function __construct(argument)

{

  # code...

 }

}

/*Null value:

Indicates that there is no value and the data is empty*/

echo null;

?>

In the above example, two basic knowledge points are supplemented: annotation and printout. Comments are intended to be remarks and have no impact on the program, but to facilitate developers to understand the program. The printout is intended to show the results.

There are two kinds of comments for PHP, for example:

//Double slashes are used for single line notes

/*This symbol is used to annotate multiple lines*/

There are three types of printouts for PHP, for example:

<?php 

/*Display string type, integer type

Floating point type, null*/

echo 123;

echo "string";

echo 0.35;

echo null;

//Display array type

print_r();

//Display array type,显示判断条件的是与非

//Than print_ R () shows more details

var_dump();

?>

Another thing to note is that every complete sentence of code must be written in English; End, otherwise an error will occur.

The above are the details of the seven data types that novices must know when getting started with PHP. If you have any supplement, you can directly contact the developeppaer editor.

Recommended Today

Beautify your code VB (VBS) code formatting implementation code

However, vb.net does have many new functions that VB6 does not have. The automatic typesetting of code is one, which is the function we want to realize today – VB code formatting.Let’s look at the effect: Before formatting: Copy codeThe code is as follows: For i = 0 To WebBrowser1.Document.All.length – 1 If WebBrowser1.Document.All(i).tagName = […]