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

Do php variables need to be defined?

藏色散人
Release: 2023-02-27 09:20:01
Original
3772 people have browsed it

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;
?>
Copy after login

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!

Related labels:
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