Source of file CombinationsArrayIterator.php
Size: 1,803 Bytes - Last Modified: 2021-12-23T10:31:32+00:00
/var/www/docs.ssmods.com/process/src/src/Utils/CombinationsArrayIterator.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 | <?php namespace SilverStripe\FullTextSearch\Utils; use Iterator; class CombinationsArrayIterator implements Iterator { protected $arrays; protected $keys; protected $numArrays; protected $isValid = false; protected $k = 0; public function __construct($args) { $this->arrays = array(); $this->keys = array(); $keys = array_keys($args); $values = array_values($args); foreach ($values as $i => $arg) { if (is_array($arg) && count($arg)) { $this->arrays[] = $arg; $this->keys[] = $keys[$i]; } } $this->numArrays = count($this->arrays); $this->rewind(); } public function rewind() { if (!$this->numArrays) { $this->isValid = false; } else { $this->isValid = true; $this->k = 0; for ($i = 0; $i < $this->numArrays; $i++) { reset($this->arrays[$i]); } } } public function valid() { return $this->isValid; } public function next() { $this->k++; for ($i = 0; $i < $this->numArrays; $i++) { if (next($this->arrays[$i]) === false) { if ($i == $this->numArrays-1) { $this->isValid = false; } else { reset($this->arrays[$i]); } } else { break; } } } public function current() { $res = array(); for ($i = 0; $i < $this->numArrays; $i++) { $res[$this->keys[$i]] = current($this->arrays[$i]); } return $res; } public function key() { return $this->k; } } |