Google News
logo
PHP Program to Case-insensitive constant name
By default, constant names in PHP are case-sensitive. However, if you want to define a constant with a case-insensitive name, you can use the `define()` function with the third argument set to `true`. This third argument tells PHP to define the constant with a case-insensitive name.

Here's an example :
Program :
<?php
define("GREETING", "Hello, world!");
define("Greeting", "Hi, there!", true);

echo GREETING . "<br>";  // outputs "Hello, world!"
echo Greeting . "<br>";  // outputs "Hi, there!"
echo greeting . "<br>";  // outputs "Hi, there!"
?>
Output :
Hello, world!
Hi, there!
Hi, there!
In this example, the `define()` function is used to define two constants. The first constant, `GREETING`, is defined with a case-sensitive name and the value `"Hello, world!"`.

The second constant, `Greeting`, is defined with a case-insensitive name and the value `"Hi, there!"`. Note that the third argument to `define()` is set to `true`, indicating that the constant should have a case-insensitive name.

The `echo` statements output the values of the constants using different cases. The first `echo` statement outputs the value of `GREETING` using the correct case. The second `echo` statement outputs the value of `Greeting` using mixed case. The third `echo` statement outputs the value of `greeting` using all lowercase letters. In all cases, the output will be "Hello, world!" for the `GREETING` constant and "Hi, there!" for the `Greeting` and `greeting` constants.