Getting Started with PHP part2

Source: Internet
Author: User
Tags getting started with php

Data Types for PHP

PHP Data types fall into three main categories,

scalar types : Integer, Float, Boolean, and string

Composite type : Array type and Object

Special type : Empty type and resource type! Resource type will speak later

shaping (int) is the numeric value of an integer.

There are three forms of representation: decimal, octal, hexadecimal.

floating-point (float) is the decimal point

There are two forms of representation: decimal form: 3.14-0.756

Exponential form: The 4.5e6=4.5x106-5.9e-2=-5.9x10-2 of Science and technology law

!!! It is best not to use floating-point numbers for comparison! Because floating-point numbers can result in the loss of data accuracy!

Boolean: only two values, True, False! Case insensitive

Integral type 0:0

Floating point 0:0.0

String 0: ' 0 '

Empty string: ', note ' (inside a space) is treated as true

NULL type: null

Empty array: Array ()

All of these are false; Resource type and object type are always true when conditions are judged

String type:

There are four ways to define strings in PHP, and it is more familiar to use single and double quotes to define them!

The difference between double quotation marks and single quotation marks;

Single quotes:

Single quotes cannot parse the variables in them!

If a single quotation mark appears in the string, you need to escape the single quotation mark! Escape character: \

Double quotation marks: Double quotation marks can parse the variables in them.

If a variable appears inside a string, it is best to wrap the variable with a variable delimiter! Variable delimiter: {$string}! {} here is only a grammatical form, not part of a string

Null type:

Assign a variable directly to NULL

Use a variable that is not defined or deleted (unset)

When a function that does not return a value is forced to return

The null type will appear above.

Recourse resource type:

PHP If you want to use external data, it is the use of resources to manage the way!

PHP is a weakly typed language, at any time in the occurrence of a type of conversion, type conversion can be divided into two kinds of one is automatic conversion of the other is cast

!! Free conversions and casts do not change the original data type.

Automatic Conversions : String types are automatically converted to numeric types! If the string does not begin with a numeric part, it is treated as a "%" when participating in the operation

Other types are automatically converted to Boolean type

Integral type 0:0

Floating point 0:0.0

String 0: ' 0 '

Empty string: ' '

NULL type: null

Empty array: Array ()

The above will come to false.

Cast:

  Syntax: (target type) raw data

(int) Convert to an integer type (float) conversion to a floating-point type (string) conversion to a String type (array) conversion to an array type (BOOL) or (Boolean) conversion to a Boolean type

Convert (object) to object type

!! You cannot cast a data to a null type and a resource type; for (array) A subsequent data item is cast to the first element of the array;

!! However, this is not a syntax for adding an array element, because the original array is emptied before the data is converted to the first element of the current array;

!! For (object), it is actually converting the subsequent data to a property of that object.

Prototype of a function

  function return value type function name (parameter 1 type parameter 1, parameter 2 type parameter 2 ...)

!! any function, consider whether it has a return value and the type of the return value, and if the function does not return a value, it is represented by void!

!! If the type of a function parameter or the type of a function return value is many, use mixed instead, which means the mixed type, also called a pseudo-type.

GetType

 Syntax: StringType (mixed $var)

  Returns the type of a data item (variable or constant or expression)! Since PHP has 8 types, it is generally considered to have 8 return values!

Settype:

Syntax: bool Settype (mixed& $var, String $type)

Sets the type of a data item (variable or constant or expression)!

Requires two parameters: the first data item to be converted; The second is what type to turn into

Returns true if the conversion succeeds, and returns false! if the conversion fails

!! The conversion here is really converting the values and types of the original data

isset:

Syntax: bool Isset (mixed& $var, [mixed $ ...] )

Determine if a variable exists!

Returns true if it exists, returns false! if it does not exist

In addition, isset can also be used to determine whether an element of an array exists! And whether the properties of the object exist!

Empty:

Syntax: bool Empty (mixed $var)

Determines whether a variable is empty, returns true if it is empty, returns false! if it is not empty

Contrary to Isset's judgement type, it can be understood that false as Isset is the true of empty.

Is_type Series :

The function of this series is to determine whether a variable is the type specified by the function, and returns a Boolean value! Here are strict judgments, in the judgment of the time will not be the type of automatic conversion!

Is_int or Is_integer

Is_float or is_double double is dual precision

Is_numeric determines whether a numeric type equals Is_int + in_float! If a string is a numeric string (all numbers inside), it is treated as a numeric data!

Is_bool

Is_string

Is_scalar scalar is the meaning of scalar, equal to is_int+is_bool+is_float+is_string

Is_array

Is_null

Is_object

Is_resource

Getting Started with PHP part2

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.