Home > Backend Development > PHP Problem > what are variables in php

what are variables in php

silencement
Release: 2023-02-25 08:54:01
Original
2834 people have browsed it

what are variables in php

Variables are containers used to store data. Variables in PHP start with the $ symbol, followed by the variable name.

Naming rules for variable names

In addition to requiring "$" to identify variable names, there are some rules that need to be followed. Just like after getting a driver's license, you still have to obey the traffic rules. There are three main naming rules for variable names:

1. The variable name must start with a letter or underscore "_", such as "$_name", "$name", "$name2", etc., but "$9name" "It's not right.

2. Variable names can only consist of letters, numbers, and "_", and can also contain Chinese characters. Such as "$_qq", "$qq308", "$my_apple", "such as "$name I'll wait", but

is "$name*" which is incorrect.

3. Variable names are not allowed to contain spaces. When the variable name consists of multiple words, it is recommended to use "_" to separate them (such as $my_apple), commonly known as the underscore method, or start with capital letters

such as $myApple, commonly known as camel formula naming method (also called camel case naming method).

It is particularly important to note that variable names in PHP are case-sensitive, such as "$my_book" and "$my_Book" represent two different variables .

<?php
    $my_book = "我的小写的book";
    $my_BOOK = "我的大写的BOOK";
 echo $my_book;
 echo "<br />";
 echo $my_BOOK;
 echo "<br />";
 $my_book = "这次奇迹要发生啦";
 echo $my_book;
 echo "<br />";
?>
Copy after login

The above is the detailed content of what are variables in php. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template