Variables in PHP:

In PHP you can store information or values in Variable so we can say that Variable is use to store information and variables can be called as “containers”.

In PHP variable declaration is start with dollar “$” keyword. A variable can store string like “Hello PHP” and integer like 6. You have to store strings always in quotes and you can store integer directly.

Syntax:
$variable_name = value;

For example:

$a = 10;

$txt = “Hello PHP”;

Note:

If you forget the dollar($) sign than it will not work.

Example:

Naming Conventions of Variables in PHP:

  • All PHP variables must start with “$” sign and followed by variable name.
  • Variable name start with a letter or the underscore character.
  • Variable name can’t start with number.
  • Variable name can only have alpha-numeric characters between (A-z, 0-9) and underscore ( _ ) in naming.
  • Variable names are case sensitive means $a and $A are two different variables.

Note:

In PHP when you assign a value to variable at that time the variable is declared or created.

One response to “Variables in PHP”

  1. Bettye K says:

    Howdy! I could have sworn I’ve visited this blog before but after
    looking at many of the posts I realized it’s neew to me.
    Regardless, I’m certainly pleased I came across it and I’ll be book-marking it and checking
    back frequently!

Leave a Reply

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