How to define a constant in PHP

4 Answers

0 votes
define("CONSTANT", "php constant");

echo CONSTANT; 


  
/*
run: 
 
php constant
   
*/ 

 



answered May 23, 2018 by avibootz
edited Dec 2, 2023 by avibootz
0 votes
define("CONSTANT", "php constant");

echo Constant; 


  
/*
run: 
 
Notice: Use of undefined constant Constant - assumed 'Constant' 
   
*/

 



answered May 23, 2018 by avibootz
edited Dec 2, 2023 by avibootz
0 votes
// define(name, value, case-insensitive)

define("CONSTANT", "php constant", true);

echo CONSTANT . "<br/>"; 
echo Constant; 



  
/*
run: 
 
php constant
php constant
   
*/  

 



answered May 23, 2018 by avibootz
edited Dec 2, 2023 by avibootz
0 votes
define("PI", 3.14);

echo PI . "\n";

echo constant("PI") . "\n";

echo PI * 2 . "\n";




/*
run:

3.14
3.14
6.28

*/

 



answered Dec 2, 2023 by avibootz

Related questions

1 answer 178 views
2 answers 201 views
201 views asked Oct 13, 2016 by avibootz
4 answers 257 views
4 answers 350 views
350 views asked Nov 2, 2015 by avibootz
2 answers 176 views
1 answer 179 views
1 answer 165 views
...