Home >Backend Development >PHP Tutorial >The function to define constants in php is
The function used to define constants in PHP is define(), its usage is as follows: define(string $name, mixed $value, bool $case_insensitive = false); Parameters: name is the name of the constant, value is The value of the constant, case_insensitive sets whether the constant name is case-sensitive (default false) Return value: None
Function to define constants in PHP
In PHP, you can use the define()
function to define constants.
Usage:
<code class="php">define(string $name, mixed $value, bool $case_insensitive = false);</code>
Parameters:
Return value:
define()
The function does not return any value.
Example:
Define a constant named GRAVITY
with a value of 9.81:
<code class="php">define('GRAVITY', 9.81);</code>
Define a constant named # Constants for ##MY_ARRAY whose value is an array:
<code class="php">define('MY_ARRAY', ['foo', 'bar', 'baz']);</code>Now, these constants can be used anywhere:
<code class="php">echo GRAVITY; // 输出 9.81 echo MY_ARRAY[0]; // 输出 foo</code>
The above is the detailed content of The function to define constants in php is. For more information, please follow other related articles on the PHP Chinese website!