🟢 Foundation · Lesson 04
Variables in PHP
Variables in PHP
PHP Variables
A variable in PHP starts with a
$ sign. You do not declare a type — PHP figures it out automatically (loosely typed).Examples
<?php
$name = "Aman";
$age = 18;
$price = 99.5;
$isStudent = true;
echo "$name is $age years old";
?>Aman is 18 years old
Variable Rules
- Must start with
$followed by a letter or underscore. - Case-sensitive:
$nameand$Nameare different. - No spaces or special characters in the name.
Summary
- PHP variables start with
$; no type declaration needed. - Case-sensitive; start with a letter or underscore.
PHP Variables
PHP में variable
$ चिह्न से शुरू होता है। आप type declare नहीं करते — PHP खुद पता लगा लेती है (loosely typed)।Examples
<?php
$name = "Aman";
$age = 18;
$price = 99.5;
$isStudent = true;
echo "$name is $age years old";
?>Aman is 18 years old
Variable नियम
$के बाद letter या underscore से शुरू हो।- Case-sensitive:
$nameऔर$Nameअलग हैं। - नाम में spaces या special characters नहीं।
सारांश
- PHP variables
$से शुरू; type declare करने की ज़रूरत नहीं। - Case-sensitive; letter या underscore से शुरू।