Summary of basic PHP knowledge

Source: Internet
Author: User

Type conversion in 1.PHP

Automatic conversion
Other type conversion numeric type
True->1
False->0
Null->0
' True '->0
' -3abc '->-3
' 3.123abc '->3.123
' 3e2av '->300
Other types convert to string type
numeric value itself
True->1
false-> empty string
null-> empty string

Array->array
Object->fatal error (fatal, cannot output object directly)
Resource->resource ID #数字

Convert other types to Boolean types
Convert to Boolean type false has
0->false
0.0->false
' or ' 0 '->false
Null->false
Array ()->false
Other will convert to True

Forced conversions
Temporary conversion
(int) | (integer)
(float) | (double) | (real)
(string)
(BOOL) | (Boolean)
(array)
(object)
(unset)
Implemented in the form of functions
Intval ($var)
Floatval ($var) |doubleval ($var)
Strval ($var)
Boolval ($var):P hp 5.5.0

Permanent conversion
BOOL Settype ($var, $type): Sets the type of the variable
Types of $type settings:
Int|integer
Float|double|real
String
Bool|boolean
Array
Object
Null
String GetType ($var): Gets the type of the variable
Common functions:
Var_dump ($var,...)
unset ($var,...)
Define constants:
Define ($name, $value [$ignore =false])
Const Name=value;
Use constants:
Direct constant Name
Constant ($NAME)
Detects if a constant name exists:
Defined ($name)
Get the defined constant name and value:
Get_defined_constants ()
Get Current version: Php_version
Get the current operating system: Php_os

Magic constants:

__LINE__: Gets the current line number
__FILE__: Absolute path to the current file
__DIR__: Get the absolute path where the file is located

__FUNCTION__:
__CLASS__:
__METHOD__:
__TRAIT__:
__NAMESPACE__:
Get the type of the variable:
Var_dump ()
GetType ()
The types of variables are detected by the variable function library:
Is_int () |is_integer () |is_long ()

Is_float () |is_double () |is_real ()

Is_string ()

Is_bool ()

Is_scalar ()

Is_null ()

Is_array ()

Is_object ()

Is_resource ()

Is_numeric ()

Ord ($char): Gets the ASCII of the specified character, returning the value of ASCII
Chr ($ASCII): Get the corresponding character based on ASCII

Summary of basic PHP knowledge

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.