note 106231 added to class.arrayiterator

From: Date: Thu, 20 Oct 2011 00:23:33 +0000
Subject: note 106231 added to class.arrayiterator
Groups: php.notes 
Request: Send a blank email to php-notes+get-184012@lists.php.net to get a copy of this message
Need a callback on an iterated value, but don't have PHP 5.4+? This makes is stupid easy: class ArrayCallbackIterator extends ArrayIterator { private $callback; public function __construct($value, $callback) { parent::__construct($value); $this->callback = $callback; } public function current() { $value = parent::current(); return call_user_func($this->callback, $value); } } You can use it pretty much exactly as the Array Iterator: $iterator1 = new ArrayCallbackIterator($valueList, "callback_function"); $iterator2 = new ArrayCallbackIterator($valueList, array($object, "callback_class_method")); ---- Server IP: 69.147.83.197 Probable Submitter: 71.227.232.71 ---- Manual Page -- http://www.php.net/manual/en/class.arrayiterator.php Edit -- https://master.php.net/note/edit/106231 Del: integrated -- https://master.php.net/note/delete/106231/integrated Del: useless -- https://master.php.net/note/delete/106231/useless Del: bad code -- https://master.php.net/note/delete/106231/bad+code Del: spam -- https://master.php.net/note/delete/106231/spam Del: non-english -- https://master.php.net/note/delete/106231/non-english Del: in docs -- https://master.php.net/note/delete/106231/in+docs Del: other reasons-- https://master.php.net/note/delete/106231 Reject -- https://master.php.net/note/reject/106231 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#184012) next »