Is that right?
<?php
Define (' Best_phper ', Array (' name ' = ' Gong wen ', ' address ' = ' China ');
My God, clearly told you not to be able to , reason is warning:constants may only evaluate to scalar values.
That is, the value of the define constant, only scalar and null are allowed. The type of scalar is integer, Float,string, or Boolean. So the array is not allowed
The usual practice is to use the following method to define "array constants" indirectly.
Method One: Using the eval () function
<?php
Define (' Best_phper ', ' Return array ' (' name ' = ' Gong wen ', ' address ' = ' China ');
$BEST _phper=eval (Best_phper);
Var_dump ($BEST _phper);
Method Two: Using the Json_encode () function
<?php
Define (' Best_phper ', Json_encode (' name ' = ' Gong wen ', ' address ' = ' China '));
$BEST _phper=json_decode (best_phper,true);
Var_dump ($BEST _phper);
Method Three: Adopt serialize () function
<?php
Define (' Best_phper ', serialize (' name ' = ' Gong wen ', ' address ' = ' China '));
$BEST _phper=unserialize (Best_phper);
Var_dump ($BEST _phper);
How PHP defines array constants