* array(key => array(0 => key_for_depth0 [, 1 => key_for_depths1, ...]),
* value => the value);
*/
- public static function fromArray(array $array, $depth = 1)
+ public static function fromArray(array $array, $depth = 1, $flat = false)
{
- return new PlArrayIterator($array, $depth);
+ return new PlArrayIterator($array, $depth, $flat);
}
private $_first;
private $_last;
private $_pos;
+ private $_flat;
- public function __construct(array &$array, $depth = 1)
+ public function __construct(array &$array, $depth = 1, $flat = false)
{
$this->array =& $array;
$this->depth = $depth;
$this->_pos = 0;
$this->_first = false;
$this->_last = false;
+ $this->_flat = $flat;
for ($i = 0 ; $i < $depth ; ++$i) {
if ($i == 0) {
$keys[] = key($this->_its[$i]);
}
next($this->_its[$this->depth - 1]);
- return array('keys' => $keys,
- 'value' => $val);
+ if ($this->_flat) {
+ return $val;
+ } else {
+ return array('keys' => $keys,
+ 'value' => $val);
+ }
}
public function total()