Conversion of PHP Data types

Source: Internet
Author: User

1. Coercion of type conversions

SetType (' variable ', ' value ')

Value: Can be any of the 8 big data types

Variables: (8 Big data types) variables that need to be converted

$var="123abc"; SetType ($var'int')  ); Var_dump ($var);

Execution result: int 123
$var="123abc"; $New= (int) $var; var_ Dump ($new);

Execution Result: int 123

2. Automatic type conversion

(most used, variables are automatically converted according to the environment)

$str ='123abc'; $int='521'; $result = $str +$int//+ number requires a numeric var_dump ($result) on both sides;

Execution Result: int 644

(Functions related to data types)

$arr=array(1,2,3,4,5); $a=getType($arr); Var_dump ($a);

Execution Result:
string
' array ' (length=5)

(Each data type will have a function to determine if this is the type)

Is_int ();

Is_float ();

Is_string ();

Is_array ();

Is_numeric (); Used to determine whether a numeric type, integral type, and float type are numeric types

$num=123; $flo=3.1415926; Var_dump (is_numeric($num)); Echo "<br/>"; Var_dump (is_numeric($flo));

Execution Result:
Boolean
True
Boolean
True

Conversion of PHP Data types

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.