Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

quoting constants in php: "this is a MY_CONSTANT"

Tags:

I want to use a constant in PHP, but I also want to put it inside double quotes like a variable. Is this at all possible?

define("TESTER", "World!"); echo "Hello, TESTER"; 

obviously outputs "Hello, TESTER", but what I really want is something like:

$tester = "World!"; echo "Hello, $tester"; 

outputs "Hello, World!".

like image 587
helloandre Avatar asked Oct 14 '09 00:10

helloandre


People also ask

What are the constants in PHP?

A constant is an identifier (name) for a simple value. The value cannot be changed during the script. A valid constant name starts with a letter or underscore (no $ sign before the constant name). Note: Unlike variables, constants are automatically global across the entire script.

Which of the following is correct about constant in PHP?

Q 2 - Which of the following is correct about constants vs variables in PHP? A - There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.

Is constant defined PHP?

A PHP constant is the opposite of a variable in that once it has been defined it cannot be changed. Constants are particularly useful for defining a value that you frequently need to refer to that does not ever change.

What is the meaning of using quotation marks in PHP?

Single or double quotes in PHP programming are used to define a string. But, there are lots of differences between these two. Single-quoted Strings: It is the easiest way to define a string. You can use it when you want the string to be exactly as it is written.


1 Answers

Sorry, that's not the way constants in PHP work. You can put variables in double quotes and heredocs but not constants.

like image 94
Dinah Avatar answered Sep 28 '22 09:09

Dinah