PHP Tutorials - How To Declare Variables in PHP - LoudProgrammer

PHP Tutorials – How To Declare Variables in PHP


Variables are like containers for storing information. In PHP a variable is declared by prepending a dollar ($) to the variable name. Unlike other programming languages, PHP has no command for declaring a variable – the variable is created the moment you first assign a value to it.

A variable name must either begin with a letter or the underscore character but it cannot start with a number. Besides, a variable name can only contain alphanumeric characters and the underscore.

In the example below we are going to declare a variable to store the name of country of a famous football star.

$country = "Brazil";

Declaring a variable is a statement in PHP and so we have to terminate it with a semicolon.

The following two tabs change content below.
Geoffrey is a lead software developer, author and writer. He writes code from scratch and frequents GitHub. He also writes and talks about technology trends, small business tips and software developer productivity hacks. He is no coffee addict.

Leave a Reply

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