PHP Data type conversions PHP data type conversions are cast, and PHP data types that allow conversion are: (int), (integer): converted to plastic (float), (double), (real): converting to floating-point (string): Converting to a string (BOOL), (Boolean): Converting to a Boolean type (array): Converting an array of (object): Converting to an object PHP Data types have three conversions: before the variable to be converted with the target type enclosed in parentheses use 3 specific types of conversion functions, intval (), Floatval (), Strval () Use common type Conversion functions Settype (mixed var,string type) The first conversion mode: (int) (bool) (float) (string) ( Array) (object) 1.<?php 2 $num 1=3.14; 3 $num 2= (int) $num 1; 4.var_dump ($num 1); Output float (3.14) 5.var_dump ($num 2); Output int (3) 6.? > The second mode of conversion: intval () floatval () strval () 1.<?php 2. $str = " 123.9abc "; 3. $int =intval ($STR); //Convert value: 123 4 $float =floatval ($STR); Value after conversion: 123.9 5. $str =strval ($float); //Convert after string: "123.9" 6.? > &NBSP;&NBSp The third mode of conversion: settype (); 1.<?php 2. $num 4=12.8; 3 $FLG =settype ($num 4, "int"); 4.var_dump ($FLG); //output bool (true) 5.var_dump ($num 4); Output int 6.? >
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.