PHP Tutorials – How To Declare Variables in PHP

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.

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

About the Author Geoffrey Barnes

Geoffrey is an experienced software developer and open source evangelist. When not coding he writes and talks about current technology trends, small business tips and developer productivity hacks. He is no coffee addict.

follow me on:

Leave a Comment: