PHP Variables

PHP variables tutorial will explain you What are variables in PHP and How to assign value to variables in PHP? with example.

  • A variable is used for storing a value such as string, numeric value or array.
  • Variable in PHP are always defined with a $,
    For e.g.
    $company = “xyz”;
    $sum = 10.0;
  • Variables in PHP are case sensitive. ($var and $VAR are two different variables)
  • Variable‚Äôs data type is changed by the value that is assigned to the variable.
  • Type casting allows changing the data type explicitly.

Variables Naming Rules:

There are few things we need to note when working with PHP variables.

    • PHP variables name might as well just begin with a letter or underscore “_”.
    • Alphanumeric characters (i.e. A-Z, a-z, and 0-9) and underscores (_) are permitted.
    • Blank spaces are not allowed.

Assigning value to Variable

A variable is useless if data is not assigned to it!

Example on Assigning value to variable:

We now have a variable called $user_name that contains a string value of “Virendra”.

Printing Variables

We can print out a variable’s value using echo.

Previous articlePHP Syntax
Next articlePHP String Variables
I am a young Information Systems Security Engineer(CEH). I had started with penetration testing when i am 17 years old. It all started with Kali linux and Metasploit.In free time i will play with Security holes/Bug bounty/Pentesting and Hacking !!!