thinkphp query returns a simple field array method _php instance

Source: Internet
Author: User
This paper describes the method of thinkphp query return simple field array, which is a very useful function in thinkphp program design. Here's how:

Typically, a SELECT statement is used. Returns an array of fields that are more complex in structure. 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": "},{", "catid": "},{", "catid": "" "},{" catid ":" "},{" catid ":"},{"catid": "},{" CATID ":" 29 "},{" CatID ":" 30 "}]

From the structure it is seen that this is a complex array of structures whose elements are a map.
If we just need a simple array that contains only the elements of a number field, you can use the following methods:

$sub _ids = D (' Category ')->where ($map)->getfield (' catid ', true);

After the query, the result is:

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

The results of the query are immediately clear and bright!

I hope that the method described in this article will be helpful to the thinkphp of our students.

  • 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.