define a constant array - PHP
This is a discussion on define a constant array - PHP ; 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...
-
define a constant array
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
print_r(eval(my_array));
Similar Threads
-
By Application Development in forum PHP
Replies: 2
Last Post: 11-05-2007, 11:13 PM
-
By Application Development in forum C
Replies: 23
Last Post: 08-28-2007, 06:54 PM
-
By Application Development in forum Javascript
Replies: 4
Last Post: 06-09-2007, 07:48 AM
-
By Application Development in forum c++
Replies: 3
Last Post: 06-01-2006, 11:30 PM
-
By Application Development in forum c++
Replies: 0
Last Post: 05-15-2006, 04:38 PM