Declaration, assignment and output of PHP constants
* 1. Three elements of constants:
* 1.1 Once created, it cannot be deleted or modified;
* 1.2 Do not add the '$' character in the header
* 1.3 Global scope, use
directly without declaration in the function * 2. Create:
* 2.1 Function: define('CONST_NAME', expression);
* 2.2 Keyword: const contName = static scalar, can be used in classes, cannot be used in functions
* 2.3 Constant names: usually only use uppercase letters and underlines, such as: ROOT_PATH
* 3. Access:
* 3.1 Keyword echo direct access: echo const_name;
* 3.2 Function: constant('constant name');
* 3.3 Function: get_defined_constants (): Get all constants
* 4. Detection: defined('constant name')
//Create constants
define('SITE_NAME','Peter Zhu的博客'); //函数define创建 const COUNTRY ='中国'; //关键字const创建
//Access constants
echo SITE_NAME,COUNTRY; //关键字echo 访问 echo '<hr>'; echo constant('SITE_NAME'); //函数constant访问 echo constant('COUNTRY'); //函数constant访问 echo '<hr><pre class="brush:php;toolbar:false">';
//Get all constants defined by the system, including user-defined
print_r(get_defined_constants()); echo '<hr>';
//Detect constants
echo defined('SITE_NAME') ? '已定义' : '未定义'; //检测常量是否已声明

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

