private$code=null;
function__construct($val)
{$this->code=$val;$this->_print();
}
private functionarrayIterator($val,$grau)
{$grau++;$arr= newArrayIterator($val);
while ($arr->valid())
{
if(is_array($arr->current()))
{$this->arrayIterator($arr->current(),$grau);
}
else
{$this->code.=str_repeat(" ", (4*$grau)) .$arr->key() ." : ".$arr->current() .PHP_EOL;
}$arr->next();
}
}
private function_print()
{
if (is_array($this->code))
{$arr= newArrayIterator($this->code);$this->code='array('.PHP_EOL;
while ($arr->valid())
{
if(is_array($arr->current()))
{$this->arrayIterator($arr->current(),0);
}
else
{$this->code.=$arr->key() ." : ".$arr->current() ."n";
}$arr->next();
}$this->code.=')';
}
return$this;
}
public functiongetVal()
{
return$this->code;
}
}$arr= array(
array('ok'=>1, array(9,7,5,9,'a','b'=>array(1,2)),'error'=>2, array('h','u','o')
)
,'array');$pArray= newPrintArray($arr);var_dump($pArray->getVal());