Site icon DataFlair

Type Casting in PHP

Program 1

<!DOCTYPE>  
<html>  
<body>  
    <center>
<?php  
    //  $a='120';// String
    //  echo"<br>Before type casting: ";
    //  var_dump($a); 
    //  $a=(int)($a);  //int
    //  echo"<br>After type casting: ";
    //  var_dump($a); 
        //  $a=123.55;
        //  echo"<br>Before type casting: ";
        //  var_dump($a); 
        //  $a=(int)($a);
        //  echo"<br>After type casting: ";
        //   var_dump($a); 

    //    $a=true;
    //    echo"<br>Before type casting: ";
    //   var_dump($a); 
    //   $a=(string)($a);  
    //   echo"<br>After type casting: ";
    //   var_dump($a); 
    //      $a='0';  //
    //       echo"<br>Before type casting: ";
    //    var_dump($a); 
    //    $a=(bool)($a);  
    //    echo"<br>After type casting: ";
    //    var_dump($a); 
             $a='Rs 500';
             echo"<br>Before type casting: ";  // 500 Rs
             
             var_dump($a); 
             $a=(int)($a);
             echo"<br>After type casting: ";  // 500
            var_dump($a);   

     /* 
        (int) -- to convert into integer
        (float) -- to convert into flaot
        (string)----- to convert into string
        (bool)----- to convert into boolean

        <> 
        
        */
?>  
</center>
</body>  
</html>

 

Exit mobile version