Home  >  Article  >  Backend Development  >  PHP constants, what are PHP constants_PHP tutorial

PHP constants, what are PHP constants_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 08:51:47972browse

php constants, what are php constants?

define() function is used to define constants. Once a constant is defined, it cannot be changed or undefined.

Example of defining constants:

<?php
define("CONSTANT", "码农教程");
echo CONSTANT;
?>

Run

Constant names follow the same naming rules as any other PHP tag. Legal constant names begin with a letter or an underscore, followed by any letters, numbers, or underscores.

Constants are case-sensitive by default. By convention, constant identifiers are always uppercase and the value cannot be changed during script execution.

The difference between defining constants and defining variables:

  • There is no dollar sign ($) in front of the constant
  • Constants can only be defined using the define() function, not assignment statements
  • Constants can be defined and accessed anywhere regardless of variable scope rules
  • Once defined, a constant cannot be redefined or undefined
  • The value of a constant can only be a scalar

PHP has a large number of built-in predefined constants, please refer to the PHP manual for details.

Original address: http://www.manongjc.com/php/php_constant.html

Related reading:

php str_pad() function completes the string to the specified length

Analysis and explanation of usage of php str_replace() string replacement function

php str_ireplace() function is case-insensitive to replace characters in a string

php str_getcsv() function parses the CSV string into an array

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1128372.htmlTechArticlephp constants, what are the php constants? The define() function is used to define constants. Once a constant is defined, it cannot be changed or undefined. Example of defining constants: ?phpdefine("CONSTA...
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