thinkPHP5-toArray()方法
2023-03-29 23:03:03
628
{{single.collect_count}}

TP5内置语句如下:

$list = $RealName_model->where($where)->order(['id' => 'desc'])->field('id,real_name,mobile,is_success')->paginate($paginate['list_rows'], false, $page_config);

该数组返回的示例如下:

think\paginator\driver\Bootstrap::__set_state(array( 'simple' => false, 'items' => think\Collection::__set_state(array( 'items' => array (0 => array ('id' => 3,'real_name' => '刘炎','mobile' => '15395110269','is_success' => 1,'order_count' => 0,'order_sum_money' => '0.00',),),)), 'currentPage' => 1, 'lastPage' => 1, 'total' => 1, 'listRows' => 15, 'hasMore' => false, 'options' => array ('var_page' => 'page','path' => '/api/Business/team_management.html','query' => array (),'fragment' => '','type' => 'bootstrap','list_rows' => 15,'merchant_id' => 1,'is_check' => 1,'page' => 1,), 'nextItem' => NULL,))

要想将以上的数据转换成数组,就要调用toArray()方法:

$list = $list->toArray();

这是thinkPHP集成好的方法,在thinkphp/library/think/collection.php文件中定义。处理之后的值就是一个规范的数组。形式如下:

array ('total' => 1,'per_page' => 15,'current_page' => 1,'last_page' => 1,'data' => array (0 => array ('id' => 3,'real_name' => '刘先生','mobile' => '15388888888','is_success' => 1,'order_count' => 0,'order_sum_money' => '0.00',),),)
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}