php中,可利用settype()函數(shù)來(lái)設(shè)置變量類(lèi)型,語(yǔ)法“settype($var,"數(shù)據(jù)類(lèi)型")”;數(shù)據(jù)類(lèi)型值可為“boolean”、“integer”、“float”、“string”、“array”、“object”、“null”。
本教程操作環(huán)境:windows7系統(tǒng)、PHP7.1版、DELL G3電腦
在php中,可利用settype()函數(shù)來(lái)設(shè)置變量類(lèi)型。
settype() 函數(shù)用于設(shè)置變量的數(shù)據(jù)類(lèi)型。(版本要求: PHP 4, PHP 5, PHP 7)
語(yǔ)法:
settype ( $var , $type ) //將變量var類(lèi)型設(shè)置成type類(lèi)型
$type的可能值為:
-
"boolean" (或?yàn)?quot;bool",從 PHP 4.2.0 起)
-
"integer" (或?yàn)?quot;int",從 PHP 4.2.0 起)
-
"float" (只在 PHP 4.2.0 之后可以使用,對(duì)于舊版本中使用的"double"現(xiàn)已停用)
-
"string"
-
"array"
-
"object"
-
"null" (從 PHP 4.2.0 起)
返回值:設(shè)置成功時(shí)返回 TRUE, 失敗時(shí)返回 FALSE。
示例:
<?php $foo = "5bar"; // string $bar = true; // boolean settype($foo, "integer"); // $foo is now 5 (integer) settype($bar, "string"); // $bar is now "1" (string) ?>
推薦學(xué)習(xí):《PHP視頻教程》