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:
Finds the first row in the result that meets the specified criteria $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 returning a result, use the $post directly->attributes; You can do it.
Post::model ()->find ()->attributes If there are multiple results returned, there are 2 ways to return an array of objects:
The first directly loops the result out of the foreach ($myReceivedCode as $model) { $result [] = $model->attributes; } The second uses array_map $result = Array_map (function ($record) { return $record->attributes; }, Post::model () ->->findallbyattributes ($attributes));
Yii Active Record Query result conversion array