Alternative to define php array

I am looking for an alternative for define('name', array), since using an array in define gives me this error:

Constants can only evaluate scalar values ​​in ...

The array that I mention contains only strings.

+4
source share
3 answers

From php.net ...

Value of a constant; only scalar and null values ​​are allowed . Scalar values ​​are integer, float, string, or boolean. You can define resource constants, but this is not recommended and can cause unpredictable behavior.

But you can do some tricks:

define('names', serialize(array('John', 'James' ...)));

& unserialize() (). , :

define('NAME1', 'John');
define('NAME2', 'James');
..

:

echo constant('NAME'.$digit);
+12

PHP, PHP

PHP 5.6, , .

+3

; :

; . integer, float, string boolean. , .

.

, , , ?

0

All Articles