Php fundamental constants


Create a constant with a case-sensitive name:

define("GREETING""Welcome to W3Schools.com!");
echo GREETING;
?>

--------

Create a constant with a case-insensitive name:

define("GREETING""Welcome to W3Schools.com!", true);
echo greeting;
?>


---------

Create an Array constant:

define("cars", [
    "Alfa Romeo",
    "BMW",
    "Toyota"
]);
echo cars[0];
?>

--------

This example uses a constant inside a function, even if it is defined outside the function:

define("GREETING""Welcome to W3Schools.com!");

function myTest() {
    echo GREETING;
}
 
myTest();
?>


--------



--------

Post a Comment

0 Comments