zms/array-paging

数组分页器

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

pkg:composer/zms/array-paging

v1.0.0 2025-11-25 10:10 UTC

This package is not auto-updated.

Last update: 2025-11-26 08:27:23 UTC


README

数组分页搜索器

数据必须是数组列表,非PHP广义的数组
    - 数组key必须是0开始自然增加
    - 数组内每一项元素的结构必须相同
//简单分页
<?php
use Zms\ArrayPaging\ArrayPaging;
$data=[
    ["code" => "2006", "name" => "辽沈银行"],
    ["code" => "2007", "name" => "滦平盛阳村镇银行"],
    ["code" => "2008", "name" => "韩城浦发村镇银行"],
    ["code" => "2009", "name" => "安徽宁国农村商业银行"],
    ["code" => "2010", "name" => "兴福村镇银行"],
    ["code" => "2011", "name" => "河间市农村信用合作联社"],
    ["code" => "2012", "name" => "河北南皮农村商业银行"],
    ["code" => "2013", "name" => "汨罗中银富登村镇银行"],
    ["code" => "2014", "name" => "陆良兴福村镇银行"],
    ["code" => "2015", "name" => "容城县农村信用合作联社王村信用社"]
];

$paging=new ArrayPaging($data,10,1);
$data=$paging->search();




//分页搜索
<?php
use \Zms\Unit\Is;
use Zms\ArrayPaging\ArrayPaging;

class ArraySearch extends ArrayPaging{

    /**
    * @desc 通过重写filter实现搜索
    * @return array
     */
    public function filter() : array{
       if(count($this->where)===0){
           return $this->data;
       }
       $result=[];
       foreach($this->data as $item){
           if(isset($this->where['code']) && Is::notEmpty($this->where['code'])){
               if($this->where['code']!==$item['code']){
                    continue;
               }
           }
            $result[]=$item;
       }
       return $result;
    }
}

$paging=new ArraySearch($data,10,1);

$paging->setWhere([
    'code'=>'3356'
]);

$data=$paging->search();