---
title: "PHP Variables"  
description: "Variable is nothing more than a name of data storage location in computer memory. Variables are used for storing values, like text strings, numbers or"  
author: "Anonymous User"  
published: 2011-09-04  
updated: 2019-09-07  
canonical: https://www.mindstick.com/articles/715/php-variables  
category: "php"  
tags: ["php"]  
reading_time: 2 minutes  

---

# PHP Variables

[Variable](https://www.mindstick.com/blog/11493/what-is-a-variable) is nothing more than a name of [data storage](https://answers.mindstick.com/qa/102476/how-does-a-computer-s-raid-configuration-enhance-data-storage) [location](https://www.mindstick.com/news/2574/twitter-conveniently-reveals-a-location-sharing-policy-amid-elonjet-controversy) in computer memory. [Variables](https://www.mindstick.com/blog/11951/types-of-variables) are used for storing values, like text [strings](https://www.mindstick.com/forum/161913/what-is-f-strings-in-python), numbers or arrays.\

Syntax: Declaring a variable in PHP.

$Variable_Name = value;

##### PHP is a loosely Typed Language:

In PHP, a variable does not need to be declared before assigning a value to it. In the above example, you see that you do not have to tell PHP, which types of variable it is. PHP automatically converts the variable to the correct data type, depending on its value. In a [strongly typed](https://www.mindstick.com/forum/298/strongly-typed-view-in-mvc) [programming](https://yourviews.mindstick.com/view/88478/vibe-coding-the-rise-of-ai-assisted-programming) [language](https://yourviews.mindstick.com/view/81607/hindi-language-in-pakistan-is-getting-killed), you have to declare or define the type and name of the variable before using it.

##### Let’s we have an example, how to use variables in PHP script.

```
<html>   <head>         <title>PHP Variables</title>   </head> <body>         <?php                 // int type variable                 $intVar = 1024;                   // string type variable                 $stringVar    ="Hello";                   // char type varaible                 $charVar = 'A';                        // float type  variable                 $floatVar     = 102.5260;                   echo "This is integer varaible";                  echo $intVar."</br>" ;                   echo "This is string variable :";                 echo $stringVar."</br>" ;                   echo "This is char variable :";                 echo $charVar."</br>" ;                        echo "This is float variable :";                 echo $floatVar."</br>";         ?> </body></html>
```

##### Desired output is:

![PHP Variables](https://www.mindstick.com/mindstickarticle/d27eca21-0f07-41c9-9c00-850256eab85b/images/b8322d18-8f7a-499e-8824-8deb6218e9af.png)

##### Naming Rule for declaring variables in PHP:

There is some rule to specify variables in PHP. The rules are…

1. Variables name must start with letter or ‘_’ (Underscore).
2. A variables name should not contains spaces. If a variable name is more than one word, it should be separated with ‘_’ (Underscore) (such as $var_name) or use capitalization word (such as $varName).
3. A variables name can only contain alpha-numeric character (like $v123ar) and underscore.

Example: Let’s we have an example, Declaring alphanumeric, underscore variable etc.

```
<html>   <head><title>Variable Convention</title></head><body>        <?php              //  Declaring   '_' (underscore)  variable              $f_name = "Arun singh";              //  Declaring alpha-numeric variables               $roll123no =123456;                            //  print underscore variable               echo $f_name ;              //  print alph-numeric varaible               echo   $roll123no ;         ?></body></html>
```

Desired output is:

![PHP Variables](https://www.mindstick.com/mindstickarticle/d27eca21-0f07-41c9-9c00-850256eab85b/images/0d277824-c78d-4a7f-ba89-25a56d3b5455.png)

---

Original Source: https://www.mindstick.com/articles/715/php-variables

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
