PHP Data Types
$integer = 42;
$float = 3.14;
$string = "text";
$boolean = true;
$array = [item1, item2];
var_dump($variable); // shows type and value
Integers
एक integer बिना किसी decimal component के एक whole number रखता है, positive या negative — counts, IDs, ages।
PHP integers को एक fixed-size binary format में store करता है, इसीलिए बहुत बड़े numbers silently एक float में overflow हो सकते हैं; ज़्यादातर everyday values के लिए यह कभी मायने नहीं रखता।
उदाहरण: Integers
<?php
// Declare `$age`, set to `30`
$age = 30;
// Declare `$id`, set to `-5`
$id = -5;
// Print a detailed dump (with types) of `$age`
var_dump($age);
?>
Login to try C/C++/Java/PHP code in the editor
Strings
एक string characters की एक sequence है — text — और इसे single या double quotes में wrap किया जाना चाहिए ताकि PHP को पता चले कि यह कहाँ शुरू और खत्म होती है।
Strings web work में PHP का सबसे ज़्यादा इस्तेमाल होने वाला type है, क्योंकि HTML output, form data, और database results fundamentally सब text हैं।
उदाहरण: Strings
<?php
// Declare `$text`, set to "Hello, world!"
$text = "Hello, world!";
// Print a detailed dump (with types) of `$text`
var_dump($text);
?>
Login to try C/C++/Java/PHP code in the editor
Floats
एक float (जिसे double भी कहते हैं) एक decimal point वाला number store करता है, या इतना बड़ा/छोटा कि इसे exponential notation चाहिए हो।
Floats fractional values वाली किसी भी चीज़ के लिए ज़रूरी हैं — prices, measurements, averages — जहाँ एक integer precision खो देगा।
उदाहरण: Floats
<?php
// Declare `$price`, set to `19.99`
$price = 19.99;
// Print a detailed dump (with types) of `$price`
var_dump($price);
?>
Login to try C/C++/Java/PHP code in the editor
Booleans
एक boolean exactly दो values में से एक रखता है, true या false, और यह आपके code में हर conditional check की backbone है। लगभग हर if statement आख़िरकार अपनी condition को एक boolean तक reduce कर देता है यह decide करने से पहले कि कौन सी branch चलानी है।
उदाहरण: Booleans
<?php
// Declare `$isActive`, set to `true`
$isActive = true;
// Print a detailed dump (with types) of `$isActive`
var_dump($isActive);
// Check whether `$isActive`
if ($isActive) {
// Print "Every if reduces to a boolean." to the output
echo "Every if reduces to a boolean.";
}
?>
Login to try C/C++/Java/PHP code in the editor
Arrays
एक array एक single variable name के तहत कई values store करता है, या तो एक numerically indexed list की तरह या key-value pairs की तरह।
आप इसे array() function या shorter [] syntax से बना सकते हैं, और arrays वह तरीका हैं जिससे PHP shopping cart से लेकर database result row तक हर चीज़ represent करता है।
उदाहरण: Arrays
<?php
// Declare `$cart`, set to `array("Apple", "Bread", "Milk")`
$cart = array("Apple", "Bread", "Milk");
// Declare `$cart2` as an array: `["Apple", "Bread", "Milk"]`
$cart2 = ["Apple", "Bread", "Milk"];
// Print a detailed dump (with types) of `$cart`
var_dump($cart);
?>
Login to try C/C++/Java/PHP code in the editor
- एक number को quotes में store करना, जैसे
$age = "25";, जो इसे एक string बना देता है;var_dumpint(25)के बजायstring(2)दिखाता है। - floats को
==से compare करना, उदाहरण के लिए0.1 + 0.2 == 0.3, जो binary floating-point rounding की वजह सेfalseहै। - यह मान लेना कि
"false"(एक non-empty string) falsy है, जबकि सिर्फ""और"0"false हैं;if ("false")block चला देता है।
Chapter Quiz — Complete all 13 topics to unlock
0/13 topics done
Complete these topics first: