Switch to full style
:read: Start PHP with us. Includes topics to help you in php
Post a reply

Type conversions

Mon Oct 27, 2008 12:38 pm

Code:
<?
$type_examples
[0] = 123;   
$type_examples[1] = 3.14159;
$type_examples[2] = "a string";
$type_examples[3] = "9.990 (begins with number)";
$type_examples[4] = array(9,8,7);
   
print(
"<TABLE><TR>");
print(
"<TH>Original</<TH>");
print(
"<TH>(int)</<TH>");
print(
"<TH>(double)</<TH>");
print(
"<TH>(string)</<TH>");
print(
"<TH>(array)</<TH></TR>");
   
for (
$index = 0; $index < 5; $index++){
    print(
"<TR><TD>$type_examples[$index]</TD>");
    
$converted_var =
       (int)
$type_examples[$index];
    print(
"<TD>$converted_var</TD>");
    
$converted_var =
       (double)
$type_examples[$index];
    print(
"<TD>$converted_var</TD>");
    
$converted_var =
       (string)
$type_examples[$index];
    print(
"<TD>$converted_var</TD>");
    
$converted_var =
       (array)
$type_examples[$index];
    print(
"<TD>$converted_var</TD></TR>");
  }
print(
"</TABLE>");
?>




Post a reply
  Related Posts  to : Type conversions
 Type Conversion     -  
 Is String a data type     -  
 String type default value     -  
 Data Type in Programming     -  
 range of the short type     -  
 range of the char type     -  
 Boolean type constant     -  
 range of data type     -  
 Create Object and get its type     -  
 set MIME type in link     -  

Topic Tags

PHP Basics, PHP Variables