4.1. Variable declaration. Operator =

In PHP, variables begin with a dollar sign ($), followed by any number of alphanumeric characters and underscores, but the first character cannot be a number. Thus, the following variable names are valid: $n, $nl, $user _ func _ 5, etc. Unlike keywords, variable names in PHP are case-sensitive, i.e. the $user, $User and $USER variables are different (Listing 4.1).

Listing 4.1. The dependence of variables on the register. File case_sensitive.php

<?php
$user = "John";
$User = "Jack";
$USER = "Michael";
echo $user; // John
echo $User; // Jack
echo $USER; // Michael

As you can see from Listing 4.1, to assign a value to a variable, you must use the assignment operator =, which allows you to initialize the variable.

When declaring numeric values, the point appears as a separator for the integer value and the fractional part (Listing 4.2).

Listing 4.2. Declaring numbers. File number_set.php

<?php
$number = 1;
$var = 3.14; 

Initialization by a single value of several variables is allowed due to the fact that the operator = returns the result of the assignment. In Listing 4.3, the variables $num, $number and $var are assigned the value 1 in one line by using the = operator in the chain.

Listing 4.3. Initializing variables with one value. multi_set.php file

<?php
$num = $number = $var = 1;