This article mainly introduces relevant information about constant knowledge in PHP. Friends who need it can refer to it
Constants in PHP are divided into custom constants and system constants
Characteristics of constants:
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
Get the value of a constant:
Use the constant name to get the value directly;
Use ==constant( )== function, it has the same effect as directly using the constant name to output, but the function can dynamically output different constants, so it must be flexible and convenient to use.
defined() function: Determine whether a constant has been defined
define("PI",3.14); $is1 = defined('PI'); $is2 = defined('PI1'); var_dump($is1); // boolean true var_dump($is2); // boolean false
##1. Custom constant
In PHP, use the ==define()== function to define a constantdefine("PI",3.14); echo constant('PI'); define("GREETING","Hello world!",TRUE); echo constant('greeting');
echo __FILE__; // E:\Web\Project\_wamp\demo.php echo __LINE__; // 3 echo PHP_VERSION; // 5.6.25 echo PHP_OS; // WINNT
PHPHow to use curl to simulate post uploading and receiving files_php tips
php mailer class calls the remote SMTP server to send mail implementation method_php skills
The above is the detailed content of Summary of knowledge about constants in PHP. For more information, please follow other related articles on the PHP Chinese website!