New: Complete Beginner's Guide to Coding is now available in Premium
Updated: Indian Govt Exam roadmaps now include salary breakdowns & timelines
Tip: Use the Career Hub to explore all career paths in one place
Tutorials PHP PHP Variables

PHP Variables

PHP

Variables in PHP start with a $ sign. No need to declare the type — PHP figures it out automatically.

Rules

  • Must start with $ followed by a letter or underscore
  • Case-sensitive: $name and $Name are different
  • No need to declare type (string, int, etc.)
Example — PHP
<?php
$name = "Rahul";
$age = 20;
$height = 5.8;
$isStudent = true;

echo "Name: " . $name . "<br>";
echo "Age: " . $age . "<br>";
echo "Height: " . $height . " feet<br>";
echo "Student: " . ($isStudent ? "Yes" : "No");
?>
Result
Name: Rahul
Age: 20
Height: 5.8 feet
Student: Yes