改變變數型態最直覺的語法就是settype(), 但這個語法就是將目標變數的型態直接進行轉變,使用時要注意:
<?
$a1="010.010abc010.010";
echo $a1."的型態為".gettype($a1)."<br>";
settype ($a1,"string");
echo '使用settype(變數,"string")後,回傳值為'.$a1.",型態為".gettype($a1)."<br>";
$a1="010.010abc010.010";
settype ($a1,"integer");
echo '使用settype(變數,"integer")後,回傳值為'.$a1.",型態為".gettype($a1)."<br>";
$a1="010.010abc010.010";
settype ($a1,"double");
echo '使用settype(變數,"double")後,回傳值為'.$a1.",型態為".gettype($a1)."<br>";
$a1="010.010abc010.010";
settype ($a1,"boolean");
echo '使用settype(變數,"boolean")後,回傳值為'.$a1.",型態為".gettype($a1)."<br>";
?>
No comments:
Post a Comment