LearnerId:

Php Programming


Content List

Skip Navigation Links.
Collapse Total Week Wise ContentTotal Week Wise Content
Collapse Week1Week1
Collapse Week2Week2
Collapse Week3Week3
Collapse Week4Week4
Collapse Week5 : DataBaseWeek5 : DataBase
Collapse Week6:Week6:
Collapse Week 7: ProjectWeek 7: Project

Data Types In PHP

Data type यह बताते है कि किसी भी variable में किस type की value store होती है अर्थात data type variable में assign value के type को define करते है । simple string and numeric type, array and object की तरह more complex data type है । PHP eight type के data type को support करता है, जो कि निम्न है-

            1.	PHP String 
            2.	PHP Integer
            3.	PHP Floating point number
            4.	PHP Boolean
            5.	PHP Array 
            6.	PHP Object
            7.	PHP Null
            8.	PHP Resource

         

1. PHP String :- String character का sequence होती है, जैसे "welcome PHP " । String के अंदर किसी भी text को हम double codes ( " " ) के अंदर लिखते है अर्थात double code के अंदर लिखा हुआ कोई text string कहलाता है । हम PHP में single code और double code दोनों use कर सकते है ।

Example

  • <?php
  • $a = "Welcome to Hello World"; // store as string data type
  • echo $a;
  • echo "<br>";
  •  
  • $b = "Learn PHP";// store as string data type
  • echo $b;
  • ?>

जब हम उपरोक्त Code को browser पर रन कराते है, तो निम्न Output प्राप्त होता है


Figure:-2 String Data Type Output



2. PHP Integer :-
 Integer value numeric value होती है ।
 यह किसी भी number को without decimal point store करने के लिए use में आती है अर्थात integer value non-decimal होती है।
 Integer number negative और positive दोनों ही हो सकते है जैसे- 521,412, -255,-321 etc.
 Integer value decimal (10-based), hexadecimal (16-based) and Octal (8-bases) format में हो सकती है

Example

  • <?php
  • $a = 230; // store as integer data type( decimal number)
  • var_dump($a) ;
  • echo "<br>";
  •  
  • $b = -125; // store as integer data type(negetive number)
  • var_dump($b) ;
  • echo "<br>";
  •  
  • $c = 0x1A; // store as integer data type(hexa-decimal)
  • var_dump($c) ;
  • ?>

जब हम उपरोक्त Code को browser पर रन कराते है, तो निम्न Output प्राप्त होता है


Figure:-2 Integer Data Type Output

उपरोक्त Program var_dump() एक function है जो कि variable की value को return करता है अर्थात दी गयी value के type को बताता है।



3. Floating Point Number :- यह numeric value को store करता है लेकिन यह decimal point वाली value को store करता है

Example

  • <?php
  • $a = 215.20; // store as floating type( non-decimal number)
  • var_dump($a) ;
  • echo "<br>";
  •  
  • $b = -21.10; // store as floating  type(non-decimal number)
  • var_dump($b) ;
  • echo "<br>";
  • ?>

जब हम उपरोक्त Code को browser पर रन कराते है, तो निम्न Output प्राप्त होता है


Figure:-3 Floating Data Type Output



4. PHP Boolean :- Boolean type केवल True या False value को ही store करता है । इसका use condition को test करने के लिए किया जाता है ।

Example

  • <?php
  • $x = true; // store as boolean type
  • $y = false; // store as boolean type
  • ?>


5. PHP Array:- Array का use एक से अधिक values को single variable में store करने के लिए किया जाता है । Array मे data elements sequentially store होते है और प्रत्येक element का एक index no होता है अर्थात Array similar type की data values का indexed collection होता है । Array की प्रत्येक index key unique और different होती है ।

Example

  • <?php
  • $country = array("India", "Australia", "Japan");
  • var_dump($country);
  • echo "<br>";
  • ?>

जब हम उपरोक्त Code को browser पर रन कराते है, तो निम्न Output प्राप्त होता है


Figure:-4 Array Data Type Output



6. PHP Object:- यह एक data type होता है जो data तथा info को store करता है। Object को explicitly declare किया जाता है ।
Object को use करने के लिए हम सदैव class declare करते है । class declare करने के लिए हम class keyword का use करते है ।
Class एक user define datatype होती है जिसके अंदर properties तथा method होते है

Example

  • <?php
  • class course{// Class definition
  •     function course(){
  •  $this->type="RSCIT, BCA, DCA";
  • }
  • }
  • $course_item = new course;    // Create object from class
  • var_dump($course_item);
  • echo "<br>";
  • echo $course_item->type;
    // show object property
  • ?>

जब हम उपरोक्त Code को browser पर रन कराते है, तो निम्न Output प्राप्त होता है


Figure:-4 Object Data Type Output



7. PHP Null:- Null value identifiers यह बताता है कि variable empty है । Null value हम केवल null variable वाले data type को ही दे सकते है । यदि कोई variable बिना किसी value के create होता है like $b , तो उसे autometically null value assign हो जाती है।
यदि $b = Null ; then $b assign null value but
यदि $b = " " ; then $b has no value

Example

  • <?php
  • $x = "Welcome India !";
  • $x = NULL;
  • var_dump($x);
  • echo "<br>";
  • ?>

जब हम उपरोक्त Code को browser पर रन कराते है, तो निम्न Output प्राप्त होता है


Figure:-5 Null Data Type Output



8. PHP Resources:- Resource एक special variable होता है जो कि external resource or functuion के reference को hold करके रखता है । Database को call करना अर्थात connecting database query , file handing आदि resource data type के लिए एक common example है ।

left right