Changing Type by Casting : Casting « Data Type « PHP






Changing Type by Casting

 
<html>
<body>
<div>
<?php
    $undecided = 3.14;
    $holder = ( double ) $undecided;
    print gettype( $holder ) ;
    print " -- $holder<br />";
    $holder = ( string ) $undecided;
    print gettype( $holder ); 
    print " -- $holder<br />";
    $holder = ( integer ) $undecided;
    print gettype( $holder ); 
    print " -- $holder<br />";
    $holder = ( double ) $undecided;
    print gettype( $holder ); 
    print " -- $holder<br />";
    $holder = ( boolean ) $undecided;
    print gettype( $holder ); 
    print " -- $holder<br />"; 
?>
</div>
</body>
</html>
  
  








Related examples in the same category

1.Casting a variable
2.Casting the return value
3.Change the data type
4.Converting to in parentheses before our variable name
5.Maintaining the integrity of the data and outputting the end result.
6.Force to change the data type by adding (int), (integer), (float), (double), or (real) in front of the variable
7.When the first expression is a string, the type of the variable will depend on the second expression.
8.convert to float
9.Typecasting
10.Casting a Variable
11.Type conversion: Approach 2
12.Type conversion: Approach 1
13.Type conversion: approach 3
14.Type conversions
15.Convert String to Date