wp-config.php
$array = array("test1","test2");
define("TEST", $array);
testFile.php
$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");
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:
And then in some other file:
However, constant are not meant to hold arrays. So, you might want to rethink your need for a constant array.
Array values can’t be used with
define
. You can only use scalar (int, float, string, bool) or null.Please see: http://php.net/manual/en/function.define.php