note 20587 added to function.array-walk
| From: | tix at ollisnet dot de | Date: | Tue, 09 Apr 2002 08:02:46 +0000 |
| Subject: | note 20587 added to function.array-walk | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-28997@lists.php.net to get a copy of this message | ||
Found out some interesting code to call a callback function which is a function of an object.
Here's an example code:
class mod {
var $thearray;
function mod( $a ) {
$this->thearray = $a;
}
function cb_modify( &$item, $key ) {
$item = "pref_".$item;
}
function modify() {
array_walk( $this->thearray, array( $this, 'cb_modify' ) );
}
}
$m = new mod(array("one","two","three"));
$m->modify();
print_r($m);
which prints out:
mod Object
(
[thearray] => Array
(
[0] => pref_one
[1] => pref_two
[2] => pref_three
)
)
As you see, the function of the object is called which modifies the array.
Greetings
TiX
--
http://www.php.net/manual/en/function.array-walk.php
http://master.php.net/manage/user-notes.php?action=edit+20587
http://master.php.net/manage/user-notes.php?action=delete+20587
http://master.php.net/manage/user-notes.php?action=reject+20587