This post is part of the PHP Snippets series where I will be covering the basics of developing in PHP.
Variables are used to store data that can be referenced and used throughout your code. In PHP, a variable is declared using a dollar sign ($) followed by the variable name:
$fruit = 'apples';
$count = 5;
Variable names in PHP are case-sensitive, must start with a letter or underscore, and can contain letters, numbers, and underscores. By convention, variable names are written in camelCase or with underscores to separate words:
$fruitName = 'apples';
$fruit_count = 5;
PHP is a loosely typed language, which means you do not need to declare the type of a variable before assigning a value to it. PHP will automatically determine the type based on the value assigned:
$fruit = 'apples'; // string
$count = 5; // integer
$price = 1.99; // float
$inStock = true; // boolean
Variables can be reassigned at any point, and their type can change when a new value is assigned:
$value = 10;
$value = 'ten';
You can check the current value of a variable at any time using echo or, for debugging purposes, var_dump() which also outputs the type:
$count = 5;
var_dump($count);
If there is a topic which fits the typical ones of this site, which you would like to see me write about, please use the form, below, to submit your idea.


