define a constant array

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi there!

I know that defining constant arrays such as:

 define('my_array',array('element_1','element_2','element_3'...) )

.. is not allowed in php..(only scalars)

Do you know any workaround about it without the use of $_SESSION ?

thanks a lot :)

Re: define a constant array

try this out:

//create php array
$arr = array('element_1', 'element_2');
//store eval code for that const
define('my_array', 'return ' . var_export($arr, 1) . ';');

//use the const array
$const = eval(my_array);

//show the const array

Site Timeline