search
Homephp教程php手册PHP教程 变量定义

PHP教程 变量定义

Jun 13, 2016 pm 12:20 PM
phpvaluevariablestringstoragedefinitionTutorialnumberarraytextset up

PHP 中的变量
变量用于存储值,比如数字、文本字符串或数组。
一旦设置了某个变量,我们就可以在脚本中重复地使用它。
PHP 中的所有变量都是以 $ 符号开始的,变量名是区分大小写的。
在 PHP 中设置变量的正确方法是:
$var_name = value;PHP 的入门者往往会忘记在变量的前面的 $ 符号。如果那样做的话,变量将是无效的。
虽然在 PHP 中并不需要初始化变量,但这是个好习惯。未初始化的变量具有其类型的默认值 - FALSE,零,空字符串或者空数组。

复制代码 代码如下:


$var = 'PHP';
$Var = '教程网';
echo "$var, $Var"; // 输出 "PHP, 教程网"
$4site = 'not yet'; // 非法变更名;以数字开头
$_4site = 'not yet'; // 合法变量名;以下划线开头
$i站点is = 'mansikka'; // 合法变量名;可以用中文
?>


变量的命名规则
变量名必须以字母或下划线 "_" 开头。
变量名只能包含字母数字字符以及下划线。
变量名不能包含空格。如果变量名由多个单词组成,那么应该使用下划线进行分隔(比如 $my_string),或者以大写字母开头(比如 $myString)。
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools