أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.
Variables and Constant both carries some defined value but difference comes with their accessibility and value.
Constant can be define as
1. define('CONSTANT_NAME', 'constant_value'); OR
2. const CONSTANT_NAME = 'constant_value';
The second way is faster than the first one.
we can not change or over-write the value of constant throughout the application, therefore we can access the same value throughout the application. Doing so will cause fatal error.
Variable:
But in case of Variable, which can contain values in array, string, integer etc. format can be over-written by the function and their accessibility scope is very rigid sometimes only for a function or class or sub-classes.
constant() function:
now Constant() function: is use to access the value of defined constant ex: constant('CONSTANT_NAME');will return value 'constant_value'; from the above example.