Type / Data type का simply मतलब है किसी variable का type जिससे हमें पता चल सके कि कोई variable किस type की value hold किये हुए है , या in future किस type की value hold करेगा।

Important
Data Type के case में PHP बहुत ही flexible language है , अगर आपको Java या C की थोड़ी भी knowledge है तो आपको याद होगा कि किसी भी तरह के variable को define करने से पहले हमें उस variable का Data Type define करना पड़ता था। मतलब हमें variable define करते समय ये बताना पड़ता था कि वह variable किस type की value store करने जा रहा है।

किसी भी variable का type किसी programmer द्वारा नहीं किया जा सकता है , यह runtime में ही assign की गयी value के according decide होता है कि variable किस type का है।

PHP 10 primitives types को support करती है।

  1. PHP scalar types :boolean : True , false
    integer : 1 2 3 4....float : 1.3 , 0.9..string : 'single qoutes' or "double qoutes"

  2. PHP compound types :array : array(value1,value2) or [value1, value2] >or ['key'=> 'value']object : class Object Ex- $x = new ClassObj();callable : will know about ititerable : like array or traversable Object

  3. PHP special types :resources : file object When we opwn file to read or write.NULL : null type की value होती है जो , जो represent करती है कि variable में कोई value नहीं है।

Note - किसी भी variable का type check करने के लिए var_dump() function का use किया जाता है , हालाँकि हम gettype() फंक्शन भी use कर सकते हैं।

Boolean

Boolean Type में maximum दो value हो सकती हैं - True or False . Boolean variable define करने के लिए just True या False Assign कर दीजिये। लेकिन जब आप Boolean value true print कराओगे तो 1 print होगा जबकि false के लिए कुछ भी print नहीं होगा।

<?php /* define boolean */ $a_bool = true;
$b_bool = False; echo "Boolean Value For True : ".$a_bool."<br>"; echo "Boolean Value For False : ".$b_bool."<br>"; ?>

Outpt

Boolean Value For True : 1
Boolean Value For False : 

Example में आप देख सकते हैं कि True के लिए 1 है जबकि false के लिए कुछ भी print नहीं हुआ है।

Integer

Integer को आप -1 , -2 . . . . 1 2 3 से डिफाइन कर सकते हैं। इसके अलावा Integer Decimal Numbers (base 10 ), Hexadecimal Numbers (base 16 ), Octa Numbers (base 8 ) और binary Numbers (base 2 ) से define कर सकते हैं।

Output

<?php /* decimal number */
$dec = 1234; /* octal number (equivalent to 83 decimal) */ $oct = 0123; /* hexadecimal number (equivalent to 26 decimal) */ $hex = 0x1A; /* binary number (equivalent to 255 decimal) */ $bin = 0b11111111; /*Now Print these values*/ echo "Hexa Deciaml Value : ".$hex ." And Type :".gettype($hex)."<br>"; echo "Deciaml Value : ".$dec ." And Type :".gettype($dec)."<br>"; echo "Octa Value : ".$oct ." And Type :".gettype($oct)."<br>"; echo "Binary Value : ".$bin ." And Type :".gettype($bin)."<br>"; ?>

Output

Hexa Deciaml Value : 26 And Type :integer
Deciaml Value : 1234 And Type :integer
Octa Value : 83 And Type :integer
Binary Value : 255 And Type :integer

Float

Floating points numbers को real numbers और double और float भी कहते हैं।

Array

PHP में Array एक ordered map है। और map एक type है जो value को key के साथ associate करता है means key value pair में data store करता है। PHP में दो type के array होते हैं।

Object

Object किसी class का instance होता है। और Class किसी Object के लिए एक Blueprint होता है। जैसे Real World Entity की कुछ Properties या Behavior होता है जिसे Programing में Class variables & methods से represent किया जाता है। ream more...

String

String series of characters या group of characters होती है , PHP में मुख्यता चार तरह से हम string define करते हैं -

  1. Single Quoted

  2. Double Quoted

  3. heredoc syntax

  4. newdoc syntax

Related Topics :

Rahul Kumar

Rahul Kumar

Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)

Get connected with me. :) LinkedIn Twitter Instagram Facebook

b2eprogrammers