for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* chdemko\BitArray\Iterator class
*
* @author Christophe Demko <[email protected]>
* @copyright Copyright (C) 2012-2024 Christophe Demko. All rights reserved.
* @license BSD 3-Clause License
* This file is part of the php-bitarray package https://github.com/chdemko/php-bitarray
*/
// Declare chdemko\BitArray namespace
namespace chdemko\BitArray;
* Iterator
* @package BitArray
* @since 1.0.0
class Iterator implements \Iterator
{
* @var integer Index
private $index;
* @var BitArray bits
private $bits;
* Constructor
* @param BitArray $bits BitArray
public function __construct(BitArray $bits)
$this->bits = $bits;
$this->rewind();
}
* Rewind the Iterator to the first element
* @return void
public function rewind(): void
$this->index = 0;
* Return the current key
* @return mixed The current key
public function key(): mixed
return $this->index;
* Return the current value
* @return mixed The current value
public function current(): mixed
return $this->bits[$this->index];
* Move forward to the next element
public function next(): void
$this->index++;
* Checks if current position is valid
* @return boolean
public function valid(): bool
return $this->index < $this->bits->size;