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.