承接 crazycodr/previous-current-iterator 相关项目开发

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

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

crazycodr/previous-current-iterator

最新稳定版本:1.1.2

Composer 安装命令:

composer require crazycodr/previous-current-iterator

包简介

Simple package that offers an iterator used for previous vs current comparison

README 文档

README

Build StatusLatest Stable Version Total Downloads Latest Unstable Version License

Previous/Current iterator

Allows iteration over an array but returns two items at a time stepping by one item at a time. Thus, the iterator for

['a', 'b', 'c', 'd']

Will return

['previous' => 'a', 'current' => 'b']
['previous' => 'b', 'current' => 'c']
['previous' => 'c', 'current' => 'd']

Current/Next iterator

Allows iteration over an array but returns two items at a time stepping by one item at a time. Thus, the iterator for

['a', 'b', 'c', 'd']

Will return

['current' => 'a', 'next' => 'b']
['current' => 'b', 'next' => 'c']
['current' => 'c', 'next' => 'd']
['current' => 'd', 'next' => null]

Installation

To install it, just include this requirement into your composer.json

{
    "require": {
        "crazycodr/previous-current-iterator": "1.*"
    }
}

And then run composer install/update as necessary.

Supports

Only PHP 5.5 or more can be supported due to the fact that key() can only return arrays starting with PHP 5.5!

Examples

To use the PreviousCurrentIterator, just instanciate a copy with an array and foreach it!

$data = ['a', 'b', 'c', 'd'];
foreach(new PreviousCurrentIterator($data) as $keys => $values) {
    //Compare previous and current
    if ($values['previous'] !== $values['current']) {
        echo 'Not the same<br />';
    }
}

To use the CurrentNextIterator, just instanciate a copy with an array and foreach it!

$data = ['a', 'b', 'c', 'd'];
foreach(new CurrentNextIterator($data) as $keys => $values) {
    //Compare previous and current
    if ($values['next'] !== null) {
        if ($values['current'] !== $values['next']) {
            echo 'Not the same<br />';
        }
    }
}

Use cases

Practical if you need to compare two items together in a previous vs current or current vs next manner.

统计信息

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

GitHub 信息

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

其他信息

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