Digital Communication


Digital Communication

PHP variables: types, declaration, usage


PHP variables offer the possibility to record data, transform it and process it. For example, you can classify sequences of characters, filter and sort arrays or perform complex calculations.

What are PHP variables?

A PHP variable is a type of container that can save information while running a PHP program in order to access it later. Variables are identified by name and can contain values ​​of different data types, for example numbers, strings of characters, Booleans or complex data structures, such as arrays or objects. Variables are often elementary components of PHP functions and PHP classes. They are used to record user inputs, save intermediate results, personalize content in web applications or manage session data. You can also call data into a MySQL database using PHP information and classify and process entries into variables.

With Deploy Now from IONOS, you are in control of your development process. Choose your Git repository and use automatic framework detection with GitHub Actions to get your app up and running. With Deploy Now, you get custom domains, SSL security, and protocol-based visitor statistics.

What is the syntax of PHP variables?

In PHP, variables are created by preceding the names of the desired variables with a dollar symbol ($), then assigning them a value. Here is the basic syntax:

The rules applicable to PHP variables are as follows:

  • Variable names : In PHP, a variable name must start with a dollar sign ($), followed by letters, numbers or underscores. The dollar symbol must be followed by a letter, not a number. For example : $maVariable, $valeur_1but never $1variable.
  • Uppercase and lowercase : PHP is case sensitive, so you need to take upper and lower case into account. So, $maVariable And $MaVariable are considered different variables.
  • Reserved words : you must not use PHP reserved words in variable names. For example, “echo”, “if”, “while”, and “foreach” are reserved words.
  • Special characters : Variable names must not contain special characters (other than the underscore) or spaces.

If you want to know more about PHP variables and their functions, we advise you to read the PHP tutorial in our guide. We have also summarized the pros and cons of PHP vs Python and PHP vs JavaScript.


Use the IONOS API at no additional cost to retrieve or update your domain, DNS and SSL data.

DNS Records

SSL Administration

API Documentation

What are the different types of PHP variables?

PHP is a poorly standardized language, so the PHP variable type is not explicitly stated. The data type is automatically detected, depending on the assigned value. This allows flexible implementation of variables in PHP. Here are some of the main data types:

  • Whole number (integer) : These data types are used to present integers without decimal places.
  • Floating point number (float) : floating point numbers, or “floats” in English, are numbers with two decimal places.
  • String : strings are made up of sequences of letters.
  • Boolean (bool) : the boolean type represents logical values ​​and can be either true (true) either false (fake).
  • Array : an array is an ordered list of values ​​that are saved under a single name. Arrays can contain values ​​of different data types.
  • Object (object) : an object is an instance of a class and can register methods and characteristics (variables).
  • NULL : NULL is a special value indicating that a variable does not have a value. So the PHP variable is definedthat is, it was set to NULL.

Examples of using PHP variables

PHP variables have many possible uses. Below we show you how you can view, associate and use globally the variables.

Echo PHP Variable

The Echo function in PHP is a simple method to display variables and their contents on the screen.

$var = "blue";
echo $var;


We obtain the following result:

Concatenating PHP variables

You can associate PHP variables with PHP operators, likeconcatenation operator .in character strings.

$var = "blue";
echo "The sky is " . $var


On the screen, the following string appears:

PHP Variable Global

In PHP you can create and initialize global variables using the super variable $GLOBALS

$GLOBALS['myVar'] = "This is a global variable";


Thanks to this assignment, the variable $myVar is global and can be accessed from any part of your PHP code.

IONOS S3 Object Storage

IONOS S3 Object Storage is ideal for backups and archiving company data. You can store any amount of static data at low cost.




Télécharger notre livre blanc

Comment construire une stratégie de marketing digital ?

Le guide indispensable pour promouvoir votre marque en ligne

En savoir plus

Web Marketing

Overview of the main SEO tools

Andriy OrlovShutterstock Overview of the Best Google SEO Tools If you want to attract as many visitors as possible to your website, you must understand

Souhaitez vous Booster votre Business?

écrivez-nous et restez en contact


© 2024 AMZ DIGICOM All Rights Reserved