PHP Variables

Declaring) PHP Variables

In PHP, a variable is declared using a $ sign followed by the variable name.

  • We don’t need to declare the data types of variable, that’s why it called loosely typed language.
  • Here we use Assignment Operator (=) to assign the value to a variable.

Rules for PHP variables:

  • A variable starts with the $ sign, followed by the name of the variable
  • It can only contain alpha-numeric character and underscore (A-z, 0-9, _).
  • A variable name must start with a letter or the underscore character
  • It cannot start with a number or special symbols.
  • Variable names are case-sensitive ($abcand $ABC are two different variables)

PHP Variable: Declaring string, integer, and float

Ex-

<?php  

$str=”hello string”;  

$integer=200;  

$float=44.6;  

echo “string is: $string <br/>“;  

echo “integer is: $integer <br/>“;  

echo “float is: $float <br/>“;  

?>  

Leave a comment

Your email address will not be published. Required fields are marked *