Home  >  Article  >  Backend Development  >  Do php variables need to be defined?

Do php variables need to be defined?

藏色散人
藏色散人Original
2019-10-18 10:23:423667browse

Do php variables need to be defined?

Do php variables need to be defined?

php variables need to be defined. Variables are containers for storing information.

PHP variable rules:

Variables start with a $ symbol, followed by the name of the variable

Variable names must start with a letter or an underscore

Variable names cannot begin with a number

Variable names can only contain alphanumeric characters and underscores (A-z, 0-9, and _)

Variable names are case-sensitive ($y and $Y are two different variables)

Note: PHP variable names are case-sensitive!

Creating PHP variables

PHP does not have a command to create variables.

The variable will be created when it is assigned a value for the first time:

Example

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

After the above statement is executed, the variable txt will save the value Hello world!, and the variable x will save the value 5, the variable y will hold the value 10.5.

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of Do php variables need to be defined?. 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