ThinkPHP query returns a simple field array _ php instance

Source: Internet
Author: User
This article describes how ThinkPHP returns a simple array of fields for query. It is a very useful technique in the ThinkPHP query function, for more information about how ThinkPHP returns a simple array of fields, see the example in this article. It is a very useful function in ThinkPHP programming. The specific method is as follows:

Generally, select statements are used. The returned fields are arrays with complex structures. The following is a simple query:

$ Map ['parentid'] = $ id; $ sub_ids = D ('category ')-> where ($ map)-> field ("catid ") -> select ();

After the query, the result is:

[{"Catid": "23" },{ "catid": "24" },{ "catid": "25" },{ "catid ": "26" },{ "catid": "27" },{ "catid": "28" },{ "catid": "29" },{ "catid ": "30"}]

From the structure, we can see that this is a complex array with a map element.
If you only need an array that contains only the number segment elements, you can use the following method:

$ Sub_ids = D ('category ')-> where ($ map)-> getField ('catid', true );

After the query, the result is:

["23", "24", "25", "26", "27", "28", "29", "30"]

The query results are now clear and clear!

I hope this method will be helpful for ThinkPHP learning.

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.