класс итератор (Отобразить)
PHP:
скопировать код в буфер обмена
скопировать код в буфер обмена
- /**
- * класс итератор для обработки CSV файлов
- */
- class CCSV implements Iterator{
- /**
- * хендл файла
- * @var resource
- */
- private $_fHandle = null
- , $_delimiter = ','
- , $_length = 1000
- , $_key = 0
- , $_currentValue = false
- , $_fEnded = false;
- /**
- * получить нынешнее значение
- */
- return $this->_currentValue;
- }
- /**
- * получить нынешний ключ
- */
- return $this->_key;
- }
- /**
- * переход на следующий элемент
- */
- $this->_key++;
- if($this->_currentValue===false)
- $this->_fEnded = true;
- return $this->_currentValue;
- }
- /**
- * сброс позиции, перемещение в начало
- */
- $this->_currentValue = null;
- if($this->_fHandle){
- $this->next();
- $this->_key=0;
- }
- }
- /**
- * проверка на существование данного элемента
- */
- public function valid(){
- if(!$this->_fEnded)
- return true;
- return false;
- }
- public function __construct($fileName, $delimiter=',', $length=1000){
- $this->_delimiter = $delimiter;
- $this->_length = $length;
- else
- }
- public function __destruct(){
- if($this->_fHandle)
- }
- }