Variables in PHP are used to store data like text, numbers, or other values. They are declared using the $
sign, followed by the variable name.
$variable_name = value;
<?php $name = "Technorank"; $age = 20; $is_online = true; echo "Name: " . $name; echo "<br>"; echo "Age: " . $age; ?>
$
followed by a letter or underscoreA-z, 0-9, _
)$var
and $Var
are different)<?php $x = 5; $y = 10; $sum = $x + $y; echo "Sum is: " . $sum; ?>
You can use echo
or print
to display variables:
<?php $greeting = "Hello"; $name = "Technorank"; echo $greeting . " " . $name; ?>
$
$username
or $price
$
followed by a name, and assign using =
. Output them using echo
or print
.
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!