Categories
PHP

PHP Variables

VARIABLE IN PHP

php variable image worldviewit

VARIABLE IN PHP

The term variable in PHP is known as the address and it holds the value. The other name for the variable is scaler. Variable assigned any symbolic name to the memory where data is stored.

Data / Value is stored in a variable with the help of EQUAL SIGN =.

So, in a program, there are values that can be used to do some action or processing and these values are stored in the variables.

Most of the time PHP variables hold temporary values in it until unless stored that value in the database.

VARIABLE DECLARATION IN PHP

PHP variable declaration is changed from other programming languages, no need to include files at the top. Just declare a variable where needs to assign a value.

$ Sign is used to declare a variable and the name of the variable is written after it without any space.

PHP VARIABLE DECLARATION EXAMPLE

<?php
//php starting tag
$a="WELCOME TO WORLDVIEWIT";
$b=1;
$c=99.9;
//Variable DECLARATION and VALUE ASSIGNING.
//closing tag of php
?>

In the upper example, we make a variable($) named "a" which is $a.

Then we assign a value to a variable $a or say that we store a value "Welcome To WORLDVIEWIT" and store 10 into $b and in the $c we stored 99.9.

Things to keep in mind before starting assigning a value to a variable in PHP.
For Text Assigning: Use quotes before text start and after the text end. And terminate the line with a semicolon ; .
For number assigning: Just write the number after the equal sign.
PHP is a case sensitive language. So variables are also cased sensitive like $xyz and $XYZ both are different.
Variable names are made using alphabets(a, z, a-z, A-Z), underscore(_), characters(0-9). 

Important Things About PHP Language

  1. In this language no need to use data type before variable declaration as in the upper example we do not label any datatype like other programming languages.
  2. So you can easily add a number (integer) with the text (string) it shows no error. 
  3. But in the PHP 7 datatype declaration used so, if appropriate data type not found in the variable it will show type mismatched error or fatal error

Leave a Reply

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