定制 steein/collections 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

steein/collections

Composer 安装命令:

composer require steein/collections

包简介

Steein Collections - Collection library for working with data. Edit

README 文档

README

Collection library for working with data.

Using Collection

use Steein\Common\Collections\Collection;

//Generated default array
$array = [
    'name'      =>  'Shamsudin',
    'project'   =>  'Steein',
    'text'      =>  'default text',

    'Cars'  =>  [
        'car_audi' =>  'Audi',
        'car_bwm'  =>  'Bmw'
    ]
];

//Default
$collection = new Collection($array);

//Or Static implementation
$collection = Collection::instance($array);

Available methods and implementation methods

In this documentation we will describe the most necessary methods, and all the rest, and you can see a lot of them in the code, everything is described there

The magic method for creating and retrieving a new item for the collection

$collection->new_array = 'value';

toArray()

Getting the collections of elements in the Array format.

$collection->toArray()

toJson()

Getting the collections of elements in the Json format.

$collection->toJson();

toXml()

Getting the collections of elements in the Json format.

$collection->toXml();

set()

New item for collection

$collection->set('key', 'value');

get()

Get the item from the collection by key.

$collection->get('key');

slice()

Create the main array of the collection.

$collection->slice(1);

nth()

Create a new collection of each n-th attribute.

$collection->nth(2);

union()

Union of collections with these elements.

$new_collection = Collection::instance([0 => ['a'], 1 => ['b'], 2 => ['c']]);
$new_collection->union([3 => ['b'], 2 => ['c']]);

combine()

Create a collection using this collection for keys, and the other for its values.

$new_collection = Collection::instance(['firstname','lastname','age']);
$new_collection->combine(['Shamsudin','Serderov', 22]);

merge()

Combine the collection with these elements.

$new_collection = Collection::instance(['id_goods' => 100,'price' => 10000, 'instock' => 0]);
$new_collection->merge(['price' => 9550, 'count' => 1]);

isEmpty()

Determine whether the collection is empty or not.

$collection->isEmpty();

isNotEmpty()

Determine if the collection is empty.

$collection->isNotEmpty();

has()

Determine if an element exists in the collection by key.

$collection->has('project');

forget()

Remove an item from the collection by key.

$collection->forget('name');

archive()

Archive the collection with one or more arrays.

$new_collection = Collection::instance(['test', 'test1']);
$new_collection->archive([50, 22]);

clear()

Clearing Attributes in the Collection

$collection->clear();

count()

Count the number of items in the collection.

$collection->count()

flip()

We turn the elements into collections.

$flip = $collection->flip();
$flip->all();

values()

Get values from items in the collection

$collection->values();

keys()

Get the keys to the attributes of the collection.

$collection->keys();

indexOf()

We search for a specific value in the collection

$collection->indexOf('Shamsudin');

all()

Get all attributes

$collection->all();

统计信息

  • 总下载量: 42
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2017-03-30

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固