search
Homephp教程php手册php入门变量

php入门变量

Jun 13, 2016 am 09:40 AM
aspnetsoftware programming

变量是用于临时存储值的容器。这些值可以是数字、文本,或者是复杂得多的数据。

PHP 具有8种变量。

其中包括4种标量(单值)类型——字符串型(字符)、整型、浮点型(小数)和布尔型(TRUE或FALSE);

两种非标量(多值)类型——数组和对象,以及资源(当与数据库交互时将看到它)和NULL(它是一种不具有任何值的特殊类型)。

============================================================================

PHP 语法规则:
1、变量的名称——也称为它的标识符——必须以美元符号($)开头,例如,$name。
2、变量名称可以包含字母、数字和下划线的组合,例如,$my_report1。
3、美元符号之后的第一个字符必须是字母或下划线(不能是数字)。
4、PHP 中的变量名称是区分大小写的。这是一个非常重要的规则。这意味着$name和$Name 是截然不同的变量。

 FAQ:

第一、可以使用等于号(= )(也称为赋值运算符)给变量赋值。

第二、无需引号即可打印变量;或者可以在双引号内打印变量;但不能在单引号内打印变量

<?php
	echo $name;				//无需引号即可打印变量
	echo "Hello, $name";	//在双引号内打印变量
	echo 'Hello, $name';	//在单引号内打印变量[会报错]
?>

 

============================================================================

【1】创建变量时最重要的考虑事项是使用一致的命名模式。有些程序员喜欢使用变量名称全都用的是小写字母,并且用下划线分隔单词($first_name);有些程序员更喜欢使用词首大写字母,例如:$FirstName(即驼峰式拼写法)。

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)