What are the advantages of defining constants using arrays?

Source: Internet
Author: User
What are the advantages of defining constants using arrays? we can see that the constant is defined using arrays in the graph. it 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']);

Reply to discussion (solution)

Is defined as an array, which is easy to print out.
For example, print_r ($ arr );

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.

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.