note 76196 deleted from function.implode by hholzgra

From: Date: Thu, 02 Aug 2012 13:18:52 +0000
Subject: note 76196 deleted from function.implode by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189743@lists.php.net to get a copy of this message
Note Submitter: peter dot goodman at gmail dot com ---- I came up with this nifty function to implode an Iterator or class that implements IteratorAggregate: function implode_iterator($sep = '', $it) { $a = array(); if(!$it instanceof Traversable) { throw new UnexpectedValueException('$it must implement Traversable.'); } if($it instanceof IteratorAggregate) { $a = iterator_to_array($it, FALSE); } else if($it instanceof Iterator) { foreach($it as $val) { $a[] = $val; } } return implode($sep, $a); }

« previous php.notes (#189743) next »