Created
May 21, 2017 05:40
-
-
Save RyujiAMANO/ecef06894c4c8af46b560c113b2d915d to your computer and use it in GitHub Desktop.
Smartyのcycleみたいなの欲しくて書いただけ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Cycle.php | |
* | |
* @author Ryuji AMANO <ryuji@ryus.co.jp> | |
*/ | |
/** | |
* Class Cycle | |
*/ | |
class Cycle { | |
/** | |
* @var array ぐるぐる回す配列 | |
*/ | |
protected $_arr; | |
/** | |
* @var int 配列内の現在位置 | |
*/ | |
protected $_current = 0; | |
/** | |
* @var int 配列の要素数 | |
*/ | |
protected $_count; | |
/** | |
* ReservationCycle constructor. | |
* | |
* @param array $arr 回すはいれつ | |
*/ | |
public function __construct($arr) { | |
$this->_arr = $arr; | |
$this->_count = count($this->_arr); | |
} | |
/** | |
* get 配列から一つとりだして、位置を次へすすめる。配列の最後まできたら先頭にもどる | |
* | |
* @return mixed | |
*/ | |
public function get() { | |
$ret = $this->_arr[$this->_current]; | |
$this->_current++; | |
if ($this->_current >= $this->_count) { | |
$this->_current = 0; | |
} | |
return $ret; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment