ThinkPHP query returns a simple field array, thinkphp array _ PHP Tutorial

Source: Internet
Author: User
ThinkPHP returns the thinkphp array as a simple field array. ThinkPHP query returns a simple field array. thinkphp array This article describes how ThinkPHP queries and returns a simple field array, thinkPHP is a very practical method in ThinkPHP programming to query and return a simple field array, thinkphp array.

The example in this article describes how ThinkPHP returns a simple array of fields for query. 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.


If the getField of thinkphp is queried by two fields, it is not the official two-dimensional array. how can this problem be solved?

Hello ~~
$ Data = $ setting-> field ('Id, TITLE')-> select ();

ThinkPHP problems: an array (all the URLs of other websites) queried from the database, and then the HTML page

That's because you didn't write http ://

Examples in this article describes how ThinkPHP queries and returns a simple array of fields, which is a very useful feature in ThinkPHP programming...

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.