itvisionsy/counter 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

itvisionsy/counter

Composer 安装命令:

composer require itvisionsy/counter

包简介

Simple PHP counter

README 文档

README

Simple counter for PHP

Why needed

Sometimes you need to display a counter steps in a loop where the index of the loop is consumed by a non-serial number.

$workHoursLog = [
    '2016-01-01'=>10,
    '2016-01-02'=>10,
    '2016-01-03'=>8,
    //...
];

As you can see, the key is not a serial number, any you may want to display in a table:

<table>
<?php foreach($workHours as $date=>$hours): ?>
    <tr>
        <td><?= Counter::nextOrInit($i, 1) ?></td>
        <td><?= $date ?></td>
        <td><?= $hours ?></td>
    </tr>
<?php endforeach; ?>
</table>

result will be

<table>
    <tr>
        <td>1</td>    
        <td>2016-01-01</td>    
        <td>10</td>    
    </tr>
    <tr>
        <td>2</td>    
        <td>2016-01-02</td>    
        <td>10</td>    
    </tr>
    <tr>
        <td>3</td>    
        <td>2016-01-03</td>    
        <td>8</td>    
    </tr>
</table>

How to use

Simply, call the nextOrInit method and pass a unique variable which will hold the counter object, optionally a second parameter which is the start, and a step:

\ItvisionSy\Counter\Counter::nextOrInit($counter,[$start=0,[$step=1]]);

Or you can initiate

//initiate
$counter = new Counter(0,1); 
//OR
Counter::nextOrInit($counter, 0, 1);

// get current value
echo $counter; 
//OR
echo $counter(); 
//OR
echo $counter->current();

//next step
$counter->next();
//OR
$counter(true);

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2016-10-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固