PHP in Hindi Data Types




Data Types सामान्य Type के होते हैं जो किसी विशेष Type की Value को Storage करने की अनुमति देते है. Data Type आकार और Type की Value को को Specified करते है जिनको Stored किया जा सकता है. Variable को Data Type की Value को Declared करने की ज़रूरत नहीं होती है. PHP मे Data Type की जांच के लिए gettype() Function का उपयोग करते है.

PHP मे कुछ Defined Variables Values को Stored करते है जब भी आप किसी भी Variable को बनाने का प्रयास करते है आपको तो हर बार Variable के लिए Data Type को Define करने की आवश्यकता नहीं होती है. लेकिन कभी कभी Situation ऐसे हो सकती है की जब Data Type की पहचान करने की आवश्यकता होती है तो तब Data Type आपके Type के Data को Specified करता है. जिसको आप अपने Variable मे Stored कर सकते है.

PHP निम्नलिखित Data Type को Supports करता है.

  • String

  • Integer

  • Float

  • Boolean

  • Array

  • Object

  • NULL

  • Resource

PHP String

एक String Characters का अनुक्रम होता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP String Example</title>
   </head>   
   <body>
      <?php 
         $x = "Hello world!";
         $y = 'Hello world!';

         echo $x;
         echo "<br>"; 
         echo $y;
      ?>

   </body>
</html>

Output

PHP String Example Hello world!
Hello world!

PHP Integer

कोई भी Integer एक Data Type और non-decimal Number के बीच होता है -2,147,483,648 and 2,147,483,647.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Integer Example</title>
   </head>   
   <body>
      <?php 
         $x = 5985;
         var_dump($x);
      ?>

   </body>
</html>

Output

PHP Float

एक Float Decimal Digits के साथ एक Number या Exponent Form मे एक Number होता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Float Example</title>
   </head>   
   <body>
      <?php 
         $x = 20.465;
         var_dump($x);
      ?>
   </body>
</html>

Output

PHP Boolean

Boolean एक Switch की तरह होता है और इसमे केवल दो Possible Values होती है TRUE या FALSE.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Boolean Example</title>
   </head>   
   <body>
      <?php 
         $x = true;
         $Y = false;
      ?>
   </body>
</html>

Output

PHP Boolean Example

PHP Array

एक Array Multiple Values को एक Single Variable मे Store करता है.

<!DOCTYPE html>
<html>
<body>

<?php
$cars = array
  (
  array("Volvo",22,18),
  array("BMW",15,13),
  array("Saab",5,2),
  array("Land Rover",17,15)
  );
  
echo $cars[0][0].": In stock: ".$cars[0][1].", sold: ".$cars[0][2].".<br>";
echo $cars[1][0].": In stock: ".$cars[1][1].", sold: ".$cars[1][2].".<br>";
echo $cars[2][0].": In stock: ".$cars[2][1].", sold: ".$cars[2][2].".<br>";
echo $cars[3][0].": In stock: ".$cars[3][1].", sold: ".$cars[3][2].".<br>";
?>

</body>
</html>

Output

Volvo: In stock: 22, sold: 18.
BMW: In stock: 15, sold: 13.
Saab: In stock: 5, sold: 2.
Land Rover: In stock: 17, sold: 15.

PHP Object

Object एक Data Type है जो Conjunct Data और जानकारी को Store करता है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP Object Example</title>
   </head>   
   <body>
      <?php 
         class Car {
            function Car() {
              $this->model = "VW";
            }
         }
         // create an object
         $herbie = new Car();

         // show object properties
         echo $herbie->model;
      ?>
   </body>
</html>

Output

PHP Object Example VW

PHP NULL Value

Null Value एक विशेष Data Type है जिसमें केवल एक Value होती है.

<!DOCTYPE html>
<html>   
   <head>
      <title>PHP NULL Value Example</title>
   </head>   
   <body>
      <?php 
         $x = "Hello world!";
         $x = null;
         var_dump($x);
      ?>

   </body>
</html>

Output