In PHP, you declare a variable using the dollar sign ($) followed by the variable name.
Syntax:
php
$variable_name = value;Examples:
php
<?php
$name = "John";
$age = 25;
$price = 99.50;
echo $name;
echo $age;
?>Rules for declaring PHP variables
A variable must start with a
$sign.The variable name must start with a letter or underscore (
_).A variable name cannot start with a number.
Variable names are case-sensitive (
$nameand$Nameare different).You do not need to specify the data type.
Remember: PHP variables are declared automatically when you assign a value to them. You don't need a keyword like int, string, or var.
0 comments:
Post a Comment
Thanks