variables

Variables and Data Types in PHP

Variables and Data Types in PHP

Variables in PHP are used to store data values. PHP automatically determines the type of variable based on its value (dynamic typing).

Declaring Variables

To declare a variable, use the $ sign followed by the variable name:

      
        <?php
          $name = "John"; // String
          $age = 30;      // Integer
          $height = 5.9;  // Float
        ?>
      
    

Common Data Types

Some common data types in PHP include:

Activity

Try It Yourself!

Declare a variable for your favorite color and echo it to the page.

Quiz

Quick Quiz

  1. What symbol is used to declare a variable in PHP?
  2. What are the basic data types in PHP?

Answers: The $ symbol; String, Integer, Float, Boolean, Array, Object.