Page 177 - CITS - Computer Software Application -TT
P. 177
COMPUTER SOFTWARE APPLICATION - CITS
PHP variables must start with letter or underscore only.
PHP variable can’t be start with numbers and special symbols.
File: variablevalid.php
File: variableinvalid.php
PHP: Loosely typed language
PHP is a loosely typed language, it means PHP automatically converts the variable to its correct data type.
PHP Constants
PHP constants are name or identifier that can’t be changed during the execution of the script except for magic
constants, which are not really constants. PHP constants can be defined by 2 ways:
1 Using define() function
2 Using const keyword
Constants are similar to the variable except once they defined, they can never be undefined or changed. They
remain constant across the entire program. PHP constants follow the same PHP variable rules. For example, it
can be started with a letter or underscore only.
Conventionally, PHP constants should be defined in uppercase letters.
Note: Unlike variables, constants are automatically global throughout the script.
PHP constant: define()
Use the define() function to create a constant. It defines constant at run time. Let’s see the syntax of define()
function in PHP.
name: It specifies the constant name.
value: It specifies the constant value.
case-insensitive: Specifies whether a constant is case-insensitive. Default value is false. It means it is case
sensitive by default.
Let’s see the example to define PHP constant using define().
164
CITS : IT&ITES - Computer Software Application - Lesson 47 - 62