Home >Backend Development >PHP Tutorial >PHP variables_PHP tutorial

PHP variables_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 09:45:17946browse

PHP variables

A variable is a variable amount in a program or used to store numbers, strings or the results of functions.

Once a variable is set, we can use it repeatedly in the script.

All variables in PHP start with the $ symbol.

The correct way to set variables in PHP is:

 $var_name = value;

Beginners to PHP often forget the $ sign in front of variables. If you do that, the variable will be invalid.

Next we create a variable that holds a string and a variable that holds a numeric value:

 

 $txt = "Hello World!";

 $number = 16;

 ?>

PHP is a loosely typed language (Loosely Typed Language)

 In PHP, there is no need to declare a variable before using it.

In the above example, you see that there is no need to declare the data type of the variable to PHP.

Depending on how the variable is set, PHP will automatically convert the variable to the correct data type.

In strongly typed programming languages, you must declare the type and name of a variable before using it.

In PHP, variables are automatically declared when used.

Naming rules for variables

 Variable names must start with a letter or underscore "_".

Variable names can only contain alphanumeric characters and underscores.

Variable names cannot contain spaces.

If the variable name consists of multiple words, they should be separated by underscores (such as $my_string), or start with a capital letter (such as $myString).

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1042525.htmlTechArticlePHP variables Variables are used to store numbers, strings, or the results of functions in a program or in varying amounts. . Once a variable is set, we can use it repeatedly in the script. ...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn