Tuesday, 16 June 2020

php data types

php datatypes

php data types
scalar types - pre defined
compund types- user defined
special types
scalar types
boolearn
integer
float
string
boolean
1. <?php   
2.     if (TRUE)  
3.         echo "This condition is TRUE.";  
This condition is TRUE.
4.     if (FALSE)  
5.         echo "This condition is FALSE.";  
6. ?>  
integer
integer can be either positive or negative and not contain deciamal point
integer can be decimal base10
octal base 8
hexadecimal
base16
 2,147,483,648 and 2,147,483,647 
<?php   
    $dec1 = 34;  
    $oct1 = 0243;  
    $hexa1 = 0x45;  
    echo "Decimal number: " .$dec1. "</br>";  
    echo "Octal number: " .$oct1. "</br>";  
    echo "HexaDecimal number: " .$hexa1. "</br>";  
?>  
Decimal number: 34
Octal number: 163
HexaDecimal number: 69
php float
it hold decimal point or fractional point and it has positive and negative sign
<?php   
    $n1 = 19.34;  
    $n2 = 54.472;  
    $sum = $n1 + $n2;  
    echo "Addition of floating numbers: " .$sum;  
?>  
Addition of floating numbers: 73.812
php string
    $company = "Javatpoint";  
 echo "Hello $company";  
php compount types
<?php   
    $bikes = array ("Royal Enfield""Yamaha""KTM");  
    var_dump($bikes);   //the var_dump() function returns the datatype and values  
    echo "</br>";  
    echo "Array Element1: $bikes[0] </br>";  
array(3) { [0]=> string(13) "Royal Enfield" [1]=> string(6) "Yamaha" [2]=> string(3) "KTM" }
    echo "Array Element2: $bikes[1] </br>";  
Array Element1: Royal Enfield
    echo "Array Element3: $bikes[2] </br>";  
Array Element2: Yamaha
?>  
Array Element3: KTM
php object
<?php   
     class bike {  
          function model() {  
               $model_name = "Royal Enfield";  
Bike Model: Royal Enfield
               echo "Bike Model: " .$model_name;  
             }  
     }  
     $obj = new bike();  
     $obj -> model();  
?>  
php special type
php resources
it is a data call
php null
<?php   
    $nl = NULL;  
    echo $nl;   //it will not give any output  
?>  



No comments:

Post a Comment