How to define constant in a function in PHP

2 Answers

0 votes
define('CONST_A', 'a');

function func() 
{
    define('CONST_B', 'b');
}

func();
echo CONST_A . " " . CONST_B;
 
/*
run:

a b

*/

 



answered Oct 13, 2016 by avibootz
0 votes
define('CONST_A', 15);

function func() 
{
    define('CONST_B', 89);
}

func();
echo CONST_A . " " . CONST_B;
 
/*
run:

15 89

*/

 



answered Oct 13, 2016 by avibootz

Related questions

4 answers 637 views
637 views asked May 23, 2018 by avibootz
1 answer 274 views
4 answers 408 views
4 answers 533 views
533 views asked Nov 2, 2015 by avibootz
...