Constants are similar to variables only in the sense that are used to store values, but otherwise, constants and variables differ in many ways.
To create a constant, it is used the define() function instead of the assignment operator (=):
define("CONSTANT_NAME", 'value', [case-insensitive]);-The case-insensitive parameter at the end of the definition is optional (a boolean value: true or false), and by default is false, meaning that the defined constant is in fact case-sensitive.
<?php define("BROTHERS", 'Victor, Alex'); define("COUSIN", "Vasile", true); // defined case-insensitive echo 'My brothers: '. BROTHERS. '<br />'; // My brothers: Victor, Alex // Try to redefine the BROTHERS constant define("BROTHERS", 'Relu'); // Notice: Constant BROTHERS already defined in ... echo 'My cousin: '. COUSIN. '<br />'; // My cousin: Vasile // assign the constant's value (the one case-insensitive) to a variable $cname = Cousin; echo 'My cousin: '. $cname; // My cousin: Vasile ?>
The scope of a defined constant is global, meaning it can be used in any defined function or class that is also part of that code file, including any other included files or functions.
<?php define("BROTHERS", 'Victor, Alex'); echo defined("BROTHERS"); // 1 ?>- The parameter with the name of the constant must be added within double quotes.
<input type="text" value="fixed-value" readonly="readonly" name="a_name" />
.class { border:2px solid blue; border-radius:1.2em; }
var ques = window.confirm("The result of 0+0 is 0?"); if (ques) alert("Corect"); else alert("Incorrect");
$min_nr = min(12, 8, 25, 13); echo $min_nr; // 8