Home  >  Article  >  Backend Development  >  What characters are allowed in php identifiers

What characters are allowed in php identifiers

(*-*)浩
(*-*)浩Original
2019-10-10 10:37:389543browse

In PHP program development, it is often necessary to customize some symbols to mark some names, such as variable names, function names, class names, etc. These symbols are called identifiers. The definition of identifiers needs to follow certain rules:

What characters are allowed in php identifiers

1. Identifiers can only be composed of letters, numbers, and underscores and cannot contain spaces.

2. Identifiers can only be composed of characters of any length starting with letters or underscores. (Recommended learning: PHP video tutorial)

3. When identifiers are used as variable names, they are case-sensitive.

4. If the identifier consists of multiple words, they should be separated by underscores.

5. Predefined keywords in PHP cannot be used

According to PHP's definition rules for identifiers, the identifiers it, It, it88, and _it are legal, while 8it and i-t are illegal identifiers

PHP variable rules:

Variables start with the $ symbol, followed by the name of the variable, and the other rules are the same as above

Creating PHP variables

PHP does not have a command to create variables.

Variables are created the first time they are assigned a value:

Instance

<?php
$txt="Hello world!";
$x=5;
$y=10.5;
?>

The above is the detailed content of What characters are allowed in php identifiers. 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