What are the advantages of using arrays to define constants?-php Tutorial

Source: Internet
Author: User
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.

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.