Introduction to PHP Data Types in Hindi
- PHP data types: scalar types
- PHP data types: compound types
- PHP data types: special types
PHP Data Types:- C Programming की तरह PHP में भी Data types होते हैं। यदि आपने C Programming पहले से ही सीखा होगा तो आपको PHP Data type आसानी से समझ आ जायेंगे। जैसे की C Programming में हम Variable बनाते हैं वैसे ही PHP में भी हम Variable बनाते हैं ।
PHP Variable
PHP में Variable बनाने के लिए हम $ sign(Dollar sign)का Use करते हैं । $ sign और Variable Name
For example
$var, $data, $date, $result etc. Variable को हम किसी भी Name से बना सकते हैं ।
Variable में Values को Store करने के लिए हम Data Type का Use करते हैं । Variable में हम किसी भी Data Type की Value को Store कर सकते हैं । PHP विभिन प्रकार के Data Type को Support करती हैं जो की निम्लिखित हैं
• String
• Integer
• Float (Floating point numbers )
• Boolean (true or false)
• Array
• Object
• NULL
• Resource
String Data Type
String Data Type Characters का Collection होता हैं । एक String विभिन तरह के Characters से बनी होती हैं । String में Numbers नहीं आते हैं । जो Data Types बिना Number के Word में Use कीए जाते हैं, उसे ही String Data Type कहाँ जाता हैं । String Data Types को Quotes के अंदर लिखा जाता हैं ।
Example
<?php $x="Hello guys I am learning PHP"; $y='Learn PHP'; echo $x; echo "<br>"; echo $y; ?>
इसी प्रकार से हम किसी भी String को Single Quotes (”)और Double Quotes(“”) में PHP को Use कर सकते हैं ।
Integer Data Type
PHP Integer Data Type Non-decimal Number होते हैं । Non-decimal Number का मतलब होता हैं जिन Numbers में कभी दशमलव नहीं आती हैं । Integer Data Type Positive और Negative दोनो हो सकते हैं ।
Positive Integer का मतलब हैं = 2
Negative Integer का मतलब हैं = – 2
Integer Data Type में कम से कम एक digit तो होनी ही हैं ।
मान लिजिए हम एक Variable में 14000 Value को Store कर देते हैं, जो की एक Integer Value हैं । उसके बाद एक fuction var_dump() का Use करते हैं, var_dump() function हमे Data Type को दिखाता हैं की हम किस Type के Data को PHP में use कर रहे हैं ।
Example
<?php $num = 14000; var_dump($num ); ?>
Float Data Type
Float Data Type Decimal Number होते हैं । Decimal Number का मतलब हैं जिनमे दशमलव(Decimal Number) आती हैं । PHP float Data Type Floating Point Number के लिए use किये जाते हैं । Floating Point का मतलब भी वही होता हैं जिन Numbers में दशमलव आती हैं ।
मान लिजिए निचे एक Variable में 30.14 float Data Type को Store करते हैं, उसके बाद var_dump() function आपको Data Type बता देता हैं की ये कौन सा Data Type हैं ।
Example
<?php $num = 30.14; var_dump($num); ?>
Boolean Data Type
Boolean Data Type दो Status को Represent करता हैं या तो true या false, Boolean का मतलब true ,false से ही होता हैं जिसमे value या तो true होती हैं, या false, PHP में Decision Time में Boolean का बहुत use किया जाता हैं । मान लिजिए दो Variable हैं और एक Variable में if Condition लगाया गया है, वह Condition true भी हो सकती हैं, और false भी ।
PHP Compiler – Best PHP Compiler in 2021 for Beginners
Example
<?php $x=40; $y=30; if($x>$y) { echo "X is true greater"; } else { echo "y is true greater"; } 0 ?>
Array
Array समान Data items का एक Collection है।Array का use बहुत सारे Data Values को एक Variable में Store करने के लिए किया जाता हैं । Array के अंदर हम Multiple Data को आसानी से store कर use कर सकते हैं।
मान लिजिए हम एक fruits के नाम से Variable Create करते हैं, जो की Array के नाम से या Array के Variable के नाम से जाना जाता हैं। इस Array में हम fruits के अलग अलग items Store कर देते हैं ।
var_dump() function की Help से हम Array का Structure और Index number देख सकते हैं।
Example
<?php $fruits = array("mango","banana","apple"); var_dump($fruits); ?>
Object data type
Object एक प्रकार का Data है जो की Data और Infomation को Store करके रखता हैं, जिसके द्वारा Function की functionality को Access किया जा सकता हैं । PHP में, object को स्पष्ट रूप से declare करना चाहिए, तभी उस object का उपयोग करके आसानी से Function की functionality को Access कर सकते हैं । Object एक Structure होती हैं जो की Properties और Methods को Contain करके रखती हैं।
दूसरे शब्दों में- Object Fuction and Methods का एक संग्रह है।
मान लिजिए एक class MObile हैं और class के अंदर एक function Mobile। इसमें हम एक Object Create करते हैं Object की Help से ही हम Fuvtion की functionality को use कर सकते हैं ।
Example
<?php class Laptop { function Laptop() { $this->model = "inspiron"; } } // create an new object $b = new Laptop (); // Show all properties echo $b->model; ?>
NULL Data Type
Null Data Type एक तरह का Variable होता हैं जिसे कोई value नहीं दी जाती। Null एक Special Data Type हैं, जिसकी केवल एक ही value होती हैं।
Example
<?php $num = "Hello we are testing ."; $num = null; var_dump($num); ?>
PHP Resource Data Type
PHP विभिन्न प्रकार के Data जैसे integer, doubleand and string etc. से संबंधित है। Resource भी PHP Data Types की List में आते हैं। लेकिन, Other Data Types के Opposite, Resource identifiers third party external application प्रदान किए गए resource Data तक पहुंचने के लिए एक reference या identifier Context के रूप में Work करते हैं।