Contenu du cours
Module 1 — Discovering PHP
Understand what PHP is, set up a local environment and write your first script.
0/4
Module 3 — Functions, arrays and forms
Create functions, work with arrays and handle data coming from a form.
0/4
PHP for beginners

A variable is a box that stores a value. In PHP, its name always starts with the $ sign, for example $firstname = « Marie »;.

The main types

  • String: text between quotes, e.g. « Hello ».
  • Integer (int): a whole number, e.g. 42.
  • Float: a decimal number, e.g. 3.14.
  • Boolean (bool): true or false.
  • Array: a list of values.

PHP works out the type on its own from the value you give: there is no need to declare it. This is called dynamic typing.

Displaying a variable

You can concatenate with a dot: echo « Hello  » . $firstname;. With double quotes, the variable is even read directly: echo « Hello $firstname »;.

Key point: a variable starts with $, stores a value, and PHP infers its type automatically.

Prix indicatifs, convertis depuis l'euro