- TOP
- Perl / PHP Web
- [PHP] class ArrayIteratorで配列の再帰処理
$fruits = array( "apple" => "yummy", "orange" => "ah ya, nice", "grape" => "wow, I love it!", "plum" => "nah, not me" ); $veg = array("potato" => "chips", "carrot" => "soup"); $grocery = array($fruits, $veg); $obj = new ArrayObject( $grocery ); $it = new RecursiveIteratorIterator( new RecursiveArrayIterator($grocery)); foreach ($it as $key=>$val) echo $key.":".$val."\n";
出力
--------
apple:yummy
orange:ah ya, nice
grape:wow, I love it!
plum:nah, not me
potato:chips
carrot:soup
http://jp2.php.net/manual/ja/class.arrayiterator.php
まんまコピペだけどコイツは便利。似たようなのにRecursiveArrayIterator クラスもある。
« [Wordpress] update_attached_fileは$fileが既存値と同じだとfalseを返す? | ホーム | [Wordpress] 管理画面上部にNoticesを出力する。 »
http://pulltab.info/mt/mt-tb.cgi/164