-->

  • php data types

    search me on youtube kumar Atul Jaiswal


    PHP DATA TYPES 

    variable can store data of differenet types and different data types can do different things.

    PHP supports the following data types:


    • String
    • Integer
    • Float
    • Boolean 
    • Array
    • Object
    • Null 
    • Resource



    PHP String
    A string is sequence of characters, like "Hello world".
    A string can be any text inside quotes. you can use single or double quotes.


    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Data types String  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $x =  "Hello world";

    echo $x;

    echo $y;?>


    </body>
    </html>





    Hello world
    kumar Atul jaiswal










    PHP Integer 

    A int data type is non decimal number between -2,123, 437,765, and 2,134, 345, 55676.

    Rules for Integers :
    • A integer have must at least one digit.
    • A integer must not have a decimal point.
    • A integer can be either positive or negative.
    • Integer can be specified in three formats : decimal ( 10 based ), hexadecimal (16-based - prefixed with 0x ) or octal ( 8 based - prefixed with 0).



    NOTE :- $x is an integer. The php var_dump() function return the data type and value.




    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Data types Integers  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $x =  58796;


    ?>

    </body>
    </html>


    Output 













    PHP Float 

    A float ( floating point number ) is a number with a decimal point or a number with exponential form.

    NOTE :- $x is a float. The php var_dump() function return the data type and value.


    Example 




    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Data types Float  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $x =  87.996;

    var_dump( $x );

    ?>

    </body>
    </html>


    Output 









    PHP Boolean 

    A Boolean represent two possible states : TRUE or FALSE.
    These data types provide output as 0 or 1. In PHP, value of True is one and the value of False is nothing.


    • x = true;
    • y = false;


    Syntax

     <?php

    $foo = True;      // assign the value TRUE to $foo

    ?>





    Example 

    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Data types Boolean</title>

    </head>
    <body>

    <h1> </h1>

     <?php  


    $x= True;          // assign the value TRUE to $b
    echo $x; 
      

    ?>

    </body>
    </html>


    Output 

    1






    Booleans are often used in conditional testing, so, you will learn about conditional testing in a later blog post of this tutorial.








    PHP Array 


    An array store multiple values in one single variable.

    In This example below $cars is an array. The php var_dump() function returns the data type and value.






    <!DOCTYPE html>
    <html>
    <head>

    <title> PHP Data types Array  </title>

    </head>
    <body>

    <h1> </h1>


    <?php

    $cars =  array ("Jaguar XJ", "Audi ", "Range rover ", " Mercedes-Benz S-Class");

    var_dump( $cars);

    ?>

    </body>
    </html>


    Output 


    array(4) { [0] => string(8) "JaguarXJ" [1]=> string[4] "Audi" [2]=> string(10) "RangeRover" [3]=> string(8) "Mercedes");


















    NOTE :- We will soon consider the topic on Boolean, Array, Object etc. 


    Have a Nice Stay Here   : - ) 







  • 0 comments:

    Post a Comment

    For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.