answersLogoWhite

0

You can define a constant using the define() directive.

you can use this a number of ways;

to define a variable to a constant do:

$string = "hello";

define("string",$string);

to define a string to a constant use:

define("hello","there");

to define a integer or other numerical value use:

define("number",1.0);

Summery:

to define a string use quotes as you would do a string.

Unlike variables in PHP a constant cannot be changed or undefined once it is defined. Constant remains automatically globally throughout the script. It means that it can be accessed from inside a function. e.g.

define("Program" , "This is my first line of code!");

function simTest() {

echo Program;

}

simTest();

?>

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

How do you define constant?

Constant means an ongoing situation or thing.


How can a PHP static be initialized?

PHP static can only be initialized using a literal or constant. You can not use an expression. You can initialize it to an integer but you may not to another variable.


How do you use constants in php?

Constants are simple pieces of data which cannot be changed during PHP script execution. It is useful for storing data which should remain unchanged, like a maximum or minimum value of a variable, etc.Before first use, constant should be defined: ...define("MY_MAX_VALUE", 505);... After this, you can use it:...if ($my_variable < MY_MAX_VALUE){... (some code here)}...


How would you declare a constant of 5 called MYCONST?

A constant of 5 called MYCONST would be declared as #define MYCONST 5. This is because the statement used is a define statement.


What is meant by .phtml?

Some people choose to run their PHP files via the .phtml extension. Web servers, such as apache, allow us to define our own extensions. For apache, you'll have to load httpd.conf and find/edit a line in similar fashion to : AddType application/x-httpd-php .php .php3 .phtml .foo : It means that PHP will parse .php .php3 .phtml and .foo files on this server.


What is slope of 0?

if you define y = constant then the slope of any constant is 0 so if you define the line y = 0 the slope of 0 is 0.


Define a specific rate constant?

The specific rate constant a proportionally determined constant that is usually different for various reactions with changes in temperature.


What are the syntax and semantics of the include construct?

The PHP syntax and semantics are the format (syntax) and the related meanings (semantics) of the text and symbols in the PHP programming language. They form a set of rules that define how a PHP program can be written and interpreted. PHP is a procedural and object-oriented language (OOL) for coding webpage markup text to be transformed into HTML format on computerized devices. In later releases, PHP generates some code to be run by the Zend Engine, beyond using just HTML markup text. The syntax of PHP changed to include OOL keywords in versions PHP 3 and PHP 5.


What is the annual mortgage constant for a 10 percent loan with a 25 year amortization?

Please define what you mean by "constant". Thank You!


How do you declare constant in Turbo C?

In C there is no constant with a name. It is done with the preprocessor directive of #define as in #define pi 3.1416 The preprocesor substitutes every occurance of word pi (with blanks on either side) with 3.1416


What is 10 percent in Php 250?

Answer: Php 2510% of Php 250= 10% * Php 250= 0.10 * Php 250= Php 25


How to make constant name case insensitive in PHP?

Generally, constant names are case sensitive in PHP.But... you can do a trick. If you will be consistent and all constant name will be defines as uppercase, you can access them using a combination of constant() and strtoupper() functions. Look at this example:?phpdefine(MY_CONSTANT, "HELLO");echo constant(strtoupper(my_constant));echo "";echo constant(strtoupper(My_Constant));echo "";echo constant(strtoupper(my_CONSTANT));?>


Write a preprocessor directive to accomplish Define symbolic constant YES to have the value 1?

I'm not exactly sure that this is a question, but here you are:#define YES 1


What is a php consultant?

PHP Consultant is a Expert PHP Developer who Guide PHP Development Process


How do you declare a constant using PHP?

Outside of a class definition, constants can be declared with the define function. The function has two arguments; the name of the constant (a string), and the value of the constant (any variable type).Inside a class definition, constants can be declared with the const keyword. Type the word const, the name of the constant in the form of how it will be called later, an "equals sign," then the desired value of the constant.In both cases, here is an example.


Define capacitive time constant in terms of charging and discharging?

The product of resistance and capacitance is referred to as the time constant. It determines rate of charging and discharging of a capacitor.


Is php a binary file?

No, PHP is text file with .php extension.


Will php 4.4.7 server support php 5 files?

Yes php 4.4.7 server support php 5 files. But most of the php 5 features are not supported by php 4.4.7 version


Does android supports PHP?

It supports websites made on php but not coding in php. There are workarounds for coding in PHP using Android.


What is new in PHP?

PHP is a recursive acronym for "PHP: Hypertext Preprocessor" created by The PHP Group. PHP is a widely used server-side scripting language and the general purpose of PHP is to create dynamic Web Pages. For more information, visit the PHP website.