Home  >  Article  >  Backend Development  >  What does a php variable name consist of?

What does a php variable name consist of?

(*-*)浩
(*-*)浩Original
2019-10-11 11:54:474112browse

What does a php variable name consist of?

Naming rules for php variables

PHP variable names cannot be randomly chosen and must follow the naming rules for php variables, as follows: (Recommended learning: PHP video tutorial)

a. It must start with a dollar sign ($), such as: $a, $b;

b, dollar sign ( The first letter after $) can only be an underscore "_" or a letter, not a number (for example: $3a is illegal);

c, the part after the dollar sign ($) can only be It consists of letters, underscores (_) and numbers;

Note:

php variable names are case-sensitive, for example: $name and $Name are two Different variables;

The naming of php variables is generally based on the meaning of the name, and is named using English words. If it consists of more than one word, capitalize the first letter of each word except the first.

Declaration of php variables

The declaration of php variables is very simple. Since php is a weak language, there is no need to specify the variable type when declaring variables. Its PHP variables can be used without declaration, and are automatically declared when used.

As shown below:

Calculate the sum of variable $number1 and variable $number2

<?php
$number1 = 3;
$number2 = 2;
$number3 = $number1+$number2;
echo $number3;
?>

The above is the detailed content of What does a php variable name consist of?. For more information, please follow other related articles on the PHP Chinese website!

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