freeCodeCamp/guide/chinese/php/constants/index.md

30 lines
874 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

---
title: Constants
localeTitle: 常量
---
## 常量
常量是PHP中的一种变量。设置常量的`define()`函数有三个参数 - 键名键的值和布尔值true或false它确定键的名称是否不区分大小写默认为false。设置后常量值不能更改。它用于很少更改的值例如数据库密码或api密钥
### 范围
重要的是要知道,与变量不同,常量总是具有全局范围,并且可以从脚本中的任何函数访问。
### 例
```PHP
<?php
define("freeCodeCamp", "Learn to code and help nonprofits", false);
echo freeCodeCamp;
```
**输出:**
```text
Learn to code and help nonprofits
```
#### 更多信息:
* [php.net常量手册](https://secure.php.net/manual/en/language.constants.php)
* [php.net define手册](https://secure.php.net/manual/en/function.define.php)