Is it possible to define an array in wp-config.php

wp-config.php

$array = array("test1","test2");
define("TEST", $array);

testFile.php

Read More
$array = TEST;

Is this possible? The above code merely sets $array to “TEST”. Or is there a way to retrieve values from wp-config.php by string i.e. something like:

$array_first_value = wp_get_config("array_first_value");

Related posts

Leave a Reply

2 comments

  1. You can serialize an array for use in a constant and unserialize it later when you need it.

    So, in wp-config.php, you could do the following:

    $array = array( "testvalue1", "testvalue2" );
    define( "TEST", serialize($array) );
    

    And then in some other file:

    $array = unserialize(TEST);
    

    However, constant are not meant to hold arrays. So, you might want to rethink your need for a constant array.