ThinkPHP查询返回简单字段数组的方法_PHP

WBOY
Release: 2016-05-31 19:30:17
Original
1202 people have browsed it

ThinkPHP

本文实例讲述了ThinkPHP查询返回简单字段数组的方法,是ThinkPHP程序设计中一个很实用的功能。具体方法如下:

通常来说使用select语句。返回的都是结构较复杂的字段数组。如以下是一个简单的查询:

$map['parentid'] = $id;
$sub_ids = D('Category')->where($map)->field("catid")->select();

Copy after login

查询后,得到的结果是:

[{"catid":"23"},{"catid":"24"},{"catid":"25"},{"catid":"26"},{"catid":"27"},{"catid":"28"},{"catid":"29"},{"catid":"30"}]

Copy after login

从结构就看出这是结构较复杂的数组,其元素是一个map。
若我们仅仅是需要一个简单的,只包含数字段元素的数组,可以使用以下方法:

$sub_ids = D('Category')->where($map)->getField('catid',true);

Copy after login

查询后,得到的结果是:

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

Copy after login

查询结果立刻清晰明朗了很多!

希望本文所述方法对于大家ThinkPHP的学习能有所帮助。

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!