Site icon TestingDocs.com

PHP Variables

Overview

PHP Variables are used to store values. We can use variables in PHP program so that we can use or manipulate later in the program. PHP is a loosely typed scripting language which means that we do not have to tell which data type the variable will hold.

Syntax

In PHP language, a variable starts with a dollar ($) sign.

$php_variable_name = value;

php_variable_name is name of the variable which holds the value. We use an assignment operator to store the value in the variable.

Naming Rules

Some variable naming rules are as follows:

A variable name can start with a letter or an underscore “_”
A variable name should not contain whitespaces.
A variable name can be comprised of alpha-numeric characters and underscores. (a-z, A-Z, 0-9, or _)

 

The IDE editor will prompt with PHP Platform variables when we type $ sign in the program. We can pick the required variables name automatically without the need of typing the whole variable name.

Example

In the following statement, we will assign a value of “79” to the variable named as “number”.

$number = 79;

Note that: Variable names are case-sensitive in PHP language. $NUMBER and $number are two different variables in PHP.

PHP Tutorials

PHP Tutorials on this website:

https://www.testingdocs.com/php-tutorials/

More Information on PHP

https://www.php.net/

Exit mobile version