Constants cannot be defined by simple assignment, they may only be defined using the define() function

">

Differences between constants and variables are?

  • There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.

  • Constants cannot be defined by simple assignment, they may only be defined using the define() function.

  • Constants may be defined and accessed anywhere without regard to variable scoping rules.

  • Once the Constants have been set, may not be redefined or undefined.

Valid and invalid constant names

// Valid constant names

define("ONE",     "first thing");

define("TWO2",    "second thing");

define("THREE_3", "third thing");

 

// Invalid constant names

define("2TWO",    "second thing");

define("__THREE__", "third value"); 

Arvind Dubey is founder of Developer Blog. He is an engineer as per his education and blogger by his profession. Before becoming a professional blogger. he decied to be his own boss and started blogging part time. His passion is blogging and under shoutmeloud, he blogs on topics like blogging tips, core php, mysql, javascript, WordPress, Web tools, SEO and so on


1406, Chember Block, Block D, Sector 14, Rohini, Delhi, 110085

Email: info@developerblog.in