Home  >  Article  >  Backend Development  >  ThinkPHP query returns a simple field array method, thinkphp array_PHP tutorial

ThinkPHP query returns a simple field array method, thinkphp array_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:19:591015browse

ThinkPHP query returns a simple field array method, thinkphp array

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.

What should I do if thinkphp’s getField queries two fields and returns something other than the official two-dimensional array?

Hello~~
$data = $setting->field('id,title')->select();

Problem in ThinkPHP: Query an array from the database (all URLs of other websites), and then query the HTML page

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/869453.htmlTechArticleThinkPHP query returns a simple field array, thinkphp array. This article describes the example of ThinkPHP query returning a simple field array. It is a very practical function in ThinkPHP programming...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn