How to pass an array as a defined constant prior Php7

User avatar
axew3
w3all User
w3all User
Posts: 2061
Joined: Fri Jan 22, 2016 5:15 pm
Location: Italy
Contact:

How to pass an array as a defined constant prior Php7

Post by axew3 »

Php 7 - Define: "Defines a named constant at runtime. In PHP 7, array values are also accepted."

But prior PHP 7, you can maybe do this, using a constant to pass an array elsewhere with define:

Code: Select all

$to_define_array = serialize($array);
define( "DEFINEANARRAY", $to_define_array );
... and so ...

Code: Select all

$serialized = DEFINEANARRAY; // passing directly the defined constant to unserialize() will not work
	  $our_array = unserialize($serialized); 

print_r($our_array);