Home > Article > Backend Development > ThinkPHP query returns a simple field array method, thinkphp array_PHP tutorial
The example in this article describes how ThinkPHP query returns a simple field array, which is a very practical function in ThinkPHP programming. The specific method is as follows:
Usually use select statements. What is returned are field arrays with more complex structures. For example, the following is a simple query:
$map['parentid'] = $id; $sub_ids = D('Category')->where($map)->field("catid")->select();
After querying, 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 an array with a more complex structure, and its element is a map.
If we just need a simple array containing only numeric field elements, we can use the following method:
$sub_ids = D('Category')->where($map)->getField('catid',true);
After querying, the result is:
["23","24","25","26","27","28","29","30"]
The query results immediately became much clearer!
I hope the method described in this article will be helpful to everyone’s learning of ThinkPHP.
Hello~~
$data = $setting->field('id,title')->select();
That’s because you didn’t write http://