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 438 views
438 views asked May 23, 2018 by avibootz
1 answer 178 views
4 answers 257 views
4 answers 350 views
350 views asked Nov 2, 2015 by avibootz
1 answer 217 views
2 answers 176 views
...