Home > Backend Development > PHP Problem > What is the usage of php define function

What is the usage of php define function

coldplay.xixi
Release: 2023-03-08 09:52:01
Original
3699 people have browsed it

php define function usage: [define()] function defines a constant, the syntax is [define(name,value,case_insensitive)], defines a case-sensitive constant, the code is [define("GREETING ","Hello 】.

What is the usage of php define function

The operating environment of this tutorial: windows7 system, PHP5.6 version, DELL G3 computer. This method is suitable for all brands of computers.

Usage of php define function:

define() The function defines a constant.

Constant is similar to a variable, except that:

  • After setting, the value of the constant cannot be changed

  • The constant name does not require a dollar sign ($) at the beginning

  • Scope does not affect access to constants

  • Constant values ​​can only be strings or numbers

Syntax

define(name,value,case_insensitive)
Copy after login

Example 1

Define a case-insensitive constant:

<?php
define("GREETING","Hello world!");
echo constant("GREETING");
?>
Copy after login

Output:

Hello world!
Copy after login
Copy after login

Example 2

Define a case-insensitive constant :

<?php
define("GREETING","Hello world!",TRUE);
echo constant("greeting");
?>
Copy after login

Output:

Hello world!
Copy after login
Copy after login

Related video recommendations: PHP programming from entry to proficiency

The above is the detailed content of What is the usage of php define function. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template