Variables in PHP

The purpose of variable to store information or any value. A variable is symbolic name that represents some data that you set. For example, age is a variable and different persons have different age. PHP is case sensitive, that means that myvars and myvars1 are two different names to PHP because they have different capitalization. PHP accepts unique variable names. Variables have much type of values (like numeric, string and logical values), in PHP every variable should be declare with $ symbol .

Variable Name Guidelines

  • Must start with alphabetical character
  • Variable names are case-sensitive
  • can't contain any periods or type-declaration characters
  • must be unique within the same scope
  • must be 255 characters or less
  • Variable must begin with a letter or the underscore character

How to use variables?

In php, variable starts with $ symbol. for example:
$age = 5;
$name = "Chris";

<?PHP
$name=”my name is mark”;
print $name;
?>

In this example we have defined two variable name, age, name has string value “mark” but age has numeric value 35, The output will display as below:

my name is mark

Another Example of PHP

<?php
$value1=35;
$value2=88;
$result=$value1+$value2;
print "Result is";
 print $result;
?>

Output

Result is 123

Bookmark This Page

Link Partners