Learn Php Data Types Best Tutorial In Hindi

PHP Data Types का Use हम Diffrent Types के Data को Hold करने के लिए करते हैं। PHP में 8 Data Types होते हैं जिन्हे 3 Categories में Divide किया गया हैं।

  1. Scalar Types (predefined)
  2. Compound Types (user-defined)
  3. Special Types

PHP Data Types: Scalar Types

Scalar Data Types केवल Single Value Hold कर सकता हैं। ये चार प्रकार के होते हैं।

  1. boolean
  2. integer
  3. float
  4. string

Boolean Data Type:

Boolean data types का Use Conditional Testing में किया जाता हैं। यह केवल दो Values को Hold कर सकता हैं जो TRUE (1) or FALSE (0) हैं। अगर कंडीशन Correct होती हैं तो ये True Return करता है, अन्यथा ये False Return करता हैं। NULL type values को भी ये False Treat करता हैं और 0 को भी। अगर कोई String Empty हैं तो यह भी False Condition में ही Consider होगी।

<?php   
    if (TRUE)  
        echo "This condition is TRUE.";  
    if (FALSE)  
        echo "This condition is FALSE.";  
?> 
PHP
Boolean Data Type In Php

Integer Data Type:

Integer Data Type केवल कम्पलीट नंबर्स को Hold करता हैं जिनमें धनात्मक और ऋणात्मक संख्याएँ शामिल होती हैं, अर्थात् वो नंबर्स जिनमे fractional part or decimal point ना हो।

Rules for integer:

  • Integer धनात्मक और ऋणात्मक कुछ भी हो सकता हैं।
  • एक Integer में दशमलव बिंदु नहीं होना चाहिए
  • Integer Decimal(Base10), Octal(Base8), या Hexadecimal(Base16) हो सकता है।
  • एक Integer की Range -2,147,483,648 और 2,147,483,647 यानी –2^31 से 2^31 के बीच होनी चाहिए।

For Example:

<?php   
    $dec1 = 11;  
    $oct1 = 0245;  
    $hexa1 = 0x45;  
    echo "Decimal number: " .$dec1. "</br>";  
    echo "Octal number: " .$oct1. "</br>";  
    echo "HexaDecimal number: " .$hexa1. "</br>";  
?> 
PHP
Integer Data Type Example In Php

Float Data Type:

Floating Point number एक दशमलव बिंदु वाली संख्या है। Integer के विपरीत, यह ऋणात्मक या धनात्मक चिह्न सहित भिन्नात्मक या दशमलव बिंदु वाली संख्याओं को Hold कर सकता है।

Example:

<?php   
    $n1 = 29.34;  
    $n2 = 24.472;  
    $sum = $n1 + $n2;  
    echo "Addition of floating numbers is: " .$sum;  
?> 
PHP
Php Float Data type in hindi

PHP String:

एक String एक Non Numeric Data Type है। String Letters या कोई Alphabets, Numbers और यहाँ तक कि Special Character को भी Hold कर सकता हैं।

Example:

<?php
  $name = "Crackexam";
  echo "The name of the Author is $name \n";
  echo 'The name of the author is $name ';
  echo "\n\n";
 
  //returns data type, size and value
  var_dump($name)
?>
PHP
Php String Data Type

PHP Data Types: Compound Types

यह Multiple values hold कर सकता है। PHP में 2 कंपाउंड डेटा टाइप होते हैं।

  1. array
  2. object

PHP Array:

Array एक Compound Data Type है। यह एक ही Data Types के कई Values को एक ही Variable में Store कर सकता है।

Exapmle:

<?php   
    $bikes = array ("Royal Enfield", "Hero Splendor", "KTM Duke", "Bajaj Pulsor");  
    var_dump($bikes);   //the var_dump() function returns the datatype and values  
    echo "</br>";  
    echo "Array Element1: $bikes[0] </br>";  
    echo "Array Element2: $bikes[1] </br>";  
    echo "Array Element3: $bikes[2] </br>";
    echo "Array Element4: $bikes[3] </br>";	
?> 
PHP
Array In Php In Hindi By Crackexam

PHP Objects:

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

Example:

Objects In php in hindi by crackexam

PHP Data Types: Special Types

PHP में 2 Special Data Types हैं।

  1. resource
  2. NULL

PHP Resource:

PHP में resource एक exact datatype नहीं हैं। मूल रूप से, इनका उपयोग कुछ Function Call या references to external PHP resources को Store करने के लिए किया जाता है।

For Example: a database call. It is an external resource.

PHP Null:

Null एक Special Data Type है जिसका केवल एक मान है: NULL। केस सेंसिटिव होने के कारण इसे बड़े अक्षरों में लिखते है।

<?php   
    $nl = NULL;  
    echo $nl;   //it will not give any output  
?> 
PHP
error: Content is protected!! You are not allowed to copy.