What are the Variables in PHP?

  1. What is a variable:

Variables are like containers.

Elements used to store data

Use that data with Variable name

2. Example 

Open a blank code editor

Open doc type HTML

Open and close PHP tag <?php  ?>

Used the $ sign followed by the name of the variable and then ;

$name = ‘Ratan’; for numbers $numbers = 100;

  • How can we use the variable?
  • echo $name;
  1. Variables are case sensitive and will end up making them a different variable if different case.
  1. Data in variable – We can store many different data types
  1. String data type – Always in quotes (texts)
  2. Numbers – Does not have quotes
  3. Floating point numbers – ones with decimals. (takes more memory)
  1. Concatenation – . Dot between two variables will smash them together
  1. Assign HTML tag to a variable = $name = “<h1> HELLO</h1>”
  1. Imp: Can only assign one value to the variables.

Leave a Reply

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