Difference between Const and Define in PHP

you can create constant with "define" keyword at run time.

for example:

$a = 10;
if( $a == 10 )
{
define('key','value');
// you can create constant at run time witg "define" keywrord .
 }


$a = 10;
if( $a == 10 )
{
Const Key = 'value';
// it will genrate an error warning because you can't create contant with "Const" Keyword  at run time.

}


for "Const" you need to intialize it first like

Const Key = 'Value';

/*
rest code here
*/

Comments