This failed:
define('DEFAULT_ROLES', array('guy', 'development team'));
Apparently, constants can't hold arrays. What is the best way to get around this?
define('DEFAULT_ROLES', 'guy|development team');
//...
$default = explode('|', DEFAULT_ROLES);
This seems like unnecessary effort.
I agree with eyze, constants tend to be single value values needed for the entire life of your application. You might think about using a configuration file instead of constants for this sort of thing.
If you really need constant arrays, you could use naming conventions to somewhat mimic arrays: for instance DB_Name, DB_USER, DB_HOST, etc.
Constants can only contain scalar values, I suggest you store the serialization (or JSON encoded representation) of the array.
You can define like this
I am using it like this. I hope, it will help others.
config.php
In file, where I need constants.
NOTE: while this is the accepted answer, it's worth noting that in PHP 5.6+ you can have const arrays - see Andrea Faulds' answer below.
You can also serialize your array and then put it into the constant:
You can store them as static variables of a class:
If you don't like the idea that the array can be changed by others, a getter might help:
EDIT
Since PHP5.4, it is even possible to access array values without the need for intermediate variables, i.e. the following works: