PHP/Data Type/settype

Материал из Web эксперт
Перейти к: навигация, поиск

Changing Type with settype()

 
<html>
<body>
<div>
<?php
    $undecided = 3.14;
    print gettype( $undecided ); 
    print " -- $undecided<br />";
    settype( $undecided, string );
    print gettype( $undecided ); 
    print " -- $undecided<br />";
    settype( $undecided, int );
    print gettype( $undecided ); 
    print " -- $undecided<br />";
    settype( $undecided, double );
    print gettype( $undecided ); 
    print " -- $undecided<br />";
    settype( $undecided, bool );
    print gettype( $undecided ); 
    print " -- $undecided<br />";
?>
</div>
</body>
</html>



Force a variable into a specific data type

 
<?php 
    $mynumber = "1.03"; 
    $mynumber = settype ($mynumber ,"integer"); 
    echo $mynumber . "<br />"; 
    echo (int) $mynumber; 
?>