thinkPHP5-toArray()方法

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',
    ),
  ),
)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值