What are the advantages of using an array to define constants? in this post, we finally edited tp_2015_1 from 2015-05-2221:29:28 to see how to define constants using arrays in the graph. I always feel so much trouble, why don't I write a constant directly, such as define (ATTACH_MALBUM, shopmember)? How good is it, but it's hard to get the whole array. what is the benefit of defining constants with arrays?
This post was last edited by tp_2015_1 at 21:29:28
As you can see in the figure, defining constants using arrays is always so troublesome. why not write a constant directly, for example
Define ('Attach _ MALBUM ', 'shop/member ');
How good,
It's incredible to bother the entire array.
What's more, I need to redefine the array in the graph in other files. isn't that an option?
Why don't we just get started? are these guys full of food?
Define ('shop _ SITE_URL ', $ config ['shop _ site_url']);
------ Solution ----------------------
It has the following benefits:
1. Simple Aggregation
2. since it is a configuration, it is possible to modify it dynamically. for example, many frameworks can modify configuration items dynamically.
3. you may need to obtain all configurations. because of the aggregation of arrays, you can easily view all configuration items.
------ Solution ----------------------
Defined constants cannot be modified.
$ Config array, which identifies the configuration information in this array.
You can also define the $ user array, which stores user information.
When you want to obtain user information, you will know to look for the $ user array. when you store too much data and forget the key name, you can print it out at a glance.
Especially during secondary development, others are not so painful to see the many variables you have defined.