When using Yii's active Record to get query results, the returned result set is an object type, and sometimes it is desirable to be able to return to the array for data processing convenience. For example, the following method:
<?php//finds the first row in the result that satisfies the specified condition $post=post::model ()->find ($condition, $params);//finds the row with the specified primary key value $post=post::model ()- >FINDBYPK ($postID, $condition, $params);//Finds the row $post=post::model ()->findbyattributes with the specified attribute value ($attributes, $ condition, $params);
when you return a result, use the $post->attributes; directly.
<?phppost::model ()->find ()->attributes
If you return multiple results, there are 2 ways to return an array of objects:
<?php//first directly outputs the result of a foreach ($myReceivedCode as $model) { $result [] = $model->attributes; } The second uses array_map $result = Array_map (function ($record) { return $record->attributes; }, Post::model () ->findallbyattributes ($attributes));
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Yii1.1 Active Record Query result conversion Group