define a constant array

define a constant array

am 09.10.2007 21:07:58 von PaowZ

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

am 10.10.2007 00:19:38 von ptdorf

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
print_r(eval(my_array));