What are the differences between PHP constants and variables?
Constant | Variables |
---|---|
In PHP, the constant is an identifier or a name for a simple value. The constant value can't be changed during script execution. | In PHP, the variable is a name or symbol which stands for value and used to store values such as characters, numeric, character string and memory addresses. |
No dollar sign ($) is required before using a constant. | Variables require a dollar sign ($) to be executed. |
It can't be defined by simple assignment. Only define() function can define it. | It is possible to define a variable by simple assignment. |
It can be redefined or undefined after it gets set. | We can redefine or undefine after it gets set. |
define('TITLE', 'Best Interview Question') | $title = 'Best Interview Question' |
BY Best Interview Question ON 24 Jul 2019