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...

+ Reply to Thread
Results 1 to 2 of 2

define a constant array

  1. Default 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


  2. Default 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));


+ Reply to Thread

Similar Threads

  1. Replies: 2
    Last Post: 11-05-2007, 11:13 PM
  2. Replies: 23
    Last Post: 08-28-2007, 06:54 PM
  3. define a constant in a virtual class
    By Application Development in forum Javascript
    Replies: 4
    Last Post: 06-09-2007, 07:48 AM
  4. Re: Elements of constant array as constant expressions.
    By Application Development in forum c++
    Replies: 3
    Last Post: 06-01-2006, 11:30 PM
  5. Re: Elements of constant array as constant expressions.
    By Application Development in forum c++
    Replies: 0
    Last Post: 05-15-2006, 04:38 PM