承接 webcodr/collection 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

webcodr/collection

最新稳定版本:2.1.4

Composer 安装命令:

composer require webcodr/collection

包简介

Collection library for PHP

README 文档

README

Build Status

PHP version

A set of array replacement classes for PHP

Requirements

  • PHP 5.4
  • Composer

Setup

Add Collection to your project

$ php composer.phar require webcodr/collection:2.*

Basic information

Collections provides two classes: MutableMap and ArrayMap

ArrayMap extends MutableMap with an implementation of the SPL interface ArrayAccess

MutableMap implements the SPL interfaces IteratorAggregate and Countable.

Both classes support a fluent interface with method chaining. Methods without a specific return value like get() or has() will return in the object itself.

Usage

A little code example says more than 1,000 words, so here we go:

The complete documentation is available in doc directory. (it's little buggy due to the use of traits)

<?php

use Collection\MutableMap;

$map = new MutableMap([
    'name' => 'William Adama',
    'rank' => 'Admiral'
]);

// getter and setter methods
echo $map->get('name'); // result = William Adama
var_dump($map->has('name')); // result = true

$map->set('commands', 'BSG 75');

// iterator method (you also use foreach() on the $map object)
$map->each(function($value, $attribute) {
    echo "{$attribute}: {$value}";
});

// update attributes with an array
$map->update([
    'name' => 'Lee Adama',
    'rank' => 'Commander',
    'commands' => 'BSG 62'
]);

echo $map->get('name'); // result = Lee Adama

// fast access with first() and last()
$battlestars = new MutableMap('Galactica', 'Pegasus', 'Atlantia');
echo $battlestars->first(); // result = Galactica
echo $battlestars->last(); // result = Atlantia

// method chaining
echo $battlestars->reverse()->last(); // result = Galactica

统计信息

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

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: JavaScript

其他信息

  • 授权协议: MIT
  • 更新时间: 2013-02-10