My Life with PHP

Datatypes available in php:

Datatype is used to specify the type of data.

What variable can hold:

Basically, we have 3 types of datatypes in php.

  1. Scalar
  2. Compound
  3. Special
Scalar datatypes again divided into different types
  1. Boolean:
  2. This datatypes represents either true or false. In php,value of True is 1, and the value of false is nothing

    Example:
    <?php
        $x=true;
        echo $x;           
    ?>
                OutPut:1 
  3. Is-bool(variable)
  4. By using this functoin, we can check whether the variable is boolean variable or not.

    Example:-
    <?php
        $x=false;
        echo is_bool($x);         
        $y="false";
        echo is_bool($y);
    ?>
                output:- 1
  5. (Bool)variable,(Boolean)variable
  6. To convert the datatype of variable into boolean datatype.

    <?php
        $y="false";
        $y=(bool)$y;
        echo is_bool($y);
    ?>
            output:- 1

Integer:

This datatype stores numeric values.

Example:

                    
                    <?php 
                    $x=123; 
                    echo $x; 
                    ?> 

output: 123

Is-int,Is-integer:

By using this function,we can check the input variable is Integer or Not.

Example:

                        
                 <?php
                 $x=123;
                 echo is-int ($x); 
                 ?>

Output: 1

(int)variable,(integer)variable,int val variable:

By using this conversion function,we can convert a variable datatype into integer datatype.

Example:

               
                <?php
                 $x="123"; 
                 $x=intval($x); 
                 echo is-int($x); 
                 ?> 

Output: 1

Float:

This datatype represents decimal values.

Is-Float:

By using this function,we can check the input value is Float or Not.

Float(variable):

By using this function,we can convert a variable datatype into a Floating Point number.

Example:

                
                <?php
                 $x=123.45;
                 echo is-Float($x); 
                 ?>

Output: 1