Home >Backend Development >PHP Problem >How to add variables in PHP? (Source code attached)
What are PHP variables, and how to set PHP variables? In this chapter, let the "newbie" take you to understand PHP for the first time, and how to become a PHP master little by little. Let's chat together
##What are variables?
Variables are "containers" used to store information; The code is as follows:<?php $x = 3; $y = 7; $z = $x + $y; echo $z; ?>
Just Like algebra in mathematics:
x=3
y=7
z=x y
z=x y, so we can get the result to be 10;
PHP variable rules:
1. Variables start with the $ symbol, followed by the name of the variable2. The variable name must start with a letter or underscore character
3. The variable name can only contain alphanumeric characters and underscores (A-z, 0-9 and _)4. Variable names cannot contain spaces 5. Variable names are case-sensitive ($y and
$Y are two different variables)
Create PHP variables
For PHP, there is no command to declare variables. The variable is created when it is assigned for the first time; The code is as follows;<?php $txt = "欢迎来到PHP中文网!"; $x = 5; $y = 11.5; ?>In the execution of the above statement, the variable txt will save the value, and the variable x will hold the value 5.
Supplement:
PHP variable scope
《PHP video tutorial》
The above is the detailed content of How to add variables in PHP? (Source code attached). For more information, please follow other related articles on the PHP Chinese website!