Home >Backend Development >PHP Tutorial >Detailed explanation of the use of define() and defined() functions in php

Detailed explanation of the use of define() and defined() functions in php

黄舟
黄舟Original
2017-11-15 11:00:412506browse

In the previous article, we introduced the use of define() in php, and the difference between define() and const in php. Today we will continue to introduce the define() function and defined() function in php. The usage is analyzed and introduced in detail, please refer to it if you need it!

The define() function defines a constant.
The define() function defines a constant.
Constants are much like variables, except for the following differences:
Constant [constant] has many similarities with variables [variable], so it is easy to confuse; below, we list the constants [constant] The difference between ] and variable [variable]:

•A constant's value cannot be changed after it is set
A constant value cannot be changed after it is specified;
•Constant names do not need a leading dollar sign ($)
When setting constants, there is no need to add the "$" sign in front;
•Constants can be accessed regardless of scope
Constant values ​​can only be strings and numbers
Constant values ​​can only be strings and numbers String
[string]" and "number[number]";

Syntax

Syntax

The code is as follows:

define(name,value,case_insensitive)

ParameterParameternameRequired. Specifies the name of the constant to check object

Example
案例

<?phpdefine("GREETING","Hello you! How are you today?");echo defined("GREETING");?>

The output of the code above will be:
上述代码将输出下面的结果:

1

总结:

本文通过示例讲述了php中define()与defined()函数的使用详解,希望对你的工作上有所帮助!

相关推荐:

php常量define与const的区别详解


php中define的使用详解


php define常量定义与变量区别_PHP教程

Description
Description

Required parameters. Specify the name of the constant

The above is the detailed content of Detailed explanation of the use of define() and defined() functions in php. For more information, please follow other related articles on the PHP Chinese website!

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