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

What is the usage of php define function

coldplay.xixi
coldplay.xixiOriginal
2021-02-25 16:50:563657browse

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)

Example 1

Define a case-insensitive constant:

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

Output:

Hello world!

Example 2

Define a case-insensitive constant :

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

Output:

Hello world!

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!

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