note 118050 added to class.arrayiterator

From: Date: Fri, 25 Sep 2015 02:28:32 +0000
Subject: note 118050 added to class.arrayiterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-203850@lists.php.net to get a copy of this message
<?php class PrintArray { private $code = null; function __construct ($val) { $this->code = $val; $this->_print(); } private function arrayIterator($val, $grau) { $grau++; $arr = new \ArrayIterator($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 = new \ArrayIterator($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 function getVal () { 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 = new PrintArray($arr); var_dump($pArray->getVal()); ---- Server IP: 72.52.91.14 Probable Submitter: 189.27.160.20 ---- Manual Page -- http://php.net/manual/en/class.arrayiterator.php Edit -- https://master.php.net/note/edit/118050 Del: integrated -- https://master.php.net/note/delete/118050/integrated Del: useless -- https://master.php.net/note/delete/118050/useless Del: bad code -- https://master.php.net/note/delete/118050/bad+code Del: spam -- https://master.php.net/note/delete/118050/spam Del: non-english -- https://master.php.net/note/delete/118050/non-english Del: in docs -- https://master.php.net/note/delete/118050/in+docs Del: other reasons-- https://master.php.net/note/delete/118050 Reject -- https://master.php.net/note/reject/118050 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#203850) next »