+ 2

What is the difference between variable and constant?

how to declare in php

26th May 2017, 8:35 AM
Rahul Panchal
Rahul Panchal - avatar
2 Answers
+ 3
A variable can be assigned with any type of information: a text string (string), integers (integer), an array, boolean values(true/false), null, etc; when declaring a variable, you assign it with an initial value. $variable_name = 'value'; PHP also allows variables change type, i.e. a variable that was formerly a string can be changed to another type of information without any problems. <?php $myVar = "hello, this is string"; $myVar = 30; $myVar = array('this','is', 'an', 'array'); $myVar = true; ?> The final value of the variable $myVariable will be true, all the rest of the assigned information is lost. A constant, as the term suggests, is an expression whose value cannot be modified throughout the script and cannot be rewritten. For defining a constant variable, conventionally capitalized names are used. Constants are global in nature. $ is not used, instead an inbuilt PHP function called define() is used.
26th May 2017, 8:55 AM
Awele Omeligwe
Awele Omeligwe - avatar
+ 2
thanks dude
26th May 2017, 8:56 AM
Rahul Panchal
Rahul Panchal - avatar