本文章来给大家转篇关于Yii 查询结果转化成数组方法,如果你对此文章有兴趣不防进入参考一下。
使用Yii 的Active Record 来获取查询结果的时候,返回的结果集是一个对象类型的,有时候为了数据处理的方便希望能够转成数组返回。比如下面的方法:
代码如下 | 复制代码 |
|
就可以了。
代码如下 | 复制代码 |
Post::model()->find()->attributes |
如果返回的是多条结果,返回的是一个对象数组的时候有下面2种方法:
代码如下 | 复制代码 |
//第一种直接将结果循环输出 foreach ($myReceivedCode as $model) { $result[] = $model->attributes; } //第二种用array_map $result= array_map(function($record) { return $record->attributes; }, Post::model()->->findAllByAttributes($attributes)); |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
