PHP variables

27 18
Read Time:1 Minute, 4 Second
Today we will learn about PHP variables.

One can use PHP variables to store informations there are some rules for PHP variables such as

  • PHP variable starts with the $ sign, and followed by name of the variable.

           for example: $text

  • PHP variable name much begin with a letter or the underscore character.
  • PHP variable name can only contain alphabetic, numeric characters and underscore.
  • Variable name should not contain spaces.
  • Variable names are case sensitive.
            for example: $text and $TEXT are two different variables.
Here is simple programme for sum of two numbers using variable.
<!DOCTYPE html>
<html>
<body>


<?php
$no1=5;
$no2=10;
$answer=$no1+$no2;
echo
$answer;
?>

</body>
</html>


——————————-
output:
15

PHP has 4 different variable scopes such as

  • local
  • global
  • static
  • parameter

Local variables are declared within a PHP function and can only access within that funcion.

Global variable is declared outside of any function and It can be accessed from any part of script.
Static variable are used when you do not want to delete local variable by using static keyword before the first declaration of the variable.
Parameter is a local variable whose value is passed to the function by the calling code.

About Post Author

Vishal Barot

Hi there, Vishal Barot here. Full-time web developer and graphic designer with over 10 years of experience. I've been experimenting with web development since I was 17 years old. If you are looking to have a professional website or design then I can develop it for you. Looking forward to working with you.
Happy
Happy
14
Sad
Sad
8
Excited
Excited
15
Sleepy
Sleepy
12
Angry
Angry
11
Surprise
Surprise
10

Leave a Comment

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