Variables, Echo & Print
Variables store data. Names start with $ and are case-sensitive. PHP creates variables when you assign a value — no let or var keyword.
Variables
Variables store data. Names start with $ and are case-sensitive. PHP creates variables when you assign a value — no let or var keyword.
Real-life example: A variable is a labeled box. $name holds "Asha" today; tomorrow you can put "Ravi" in the same box.
<?php
$name = "Asha";
$age = 22;
$price = 1999.50;
$isStudent = true;
echo "Name: $name, Age: $age";
?>Echo
echo is the most common way to output text. It accepts multiple comma-separated strings and works inside double-quoted strings with variables.
Real-life example: echo is a loudspeaker — you announce text to the page visitor.
<?php
$course = "PHP";
echo "Learning ", $course, " on Rishtaara!";
echo "<br>Line two";
?>print is like echo but returns 1 and accepts only one argument. Most developers prefer echo because it is slightly faster and more flexible.
Real-life example: print is a single-page flyer. echo is a stack of flyers — you can hand out many at once.
<?php
$msg = "Hello from Rishtaara";
print $msg; // returns 1
echo $msg; // preferred in most code
?>