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 194 views
2 answers 215 views
215 views asked Oct 13, 2016 by avibootz
4 answers 270 views
4 answers 364 views
364 views asked Nov 2, 2015 by avibootz
...