note 20587 deleted from function.array-walk by aidan

From: Date: Sun, 11 Jul 2004 02:10:29 +0000
Subject: note 20587 deleted from function.array-walk by aidan
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-73037@lists.php.net to get a copy of this message
Note Submitter: tix@ollisnet.de ---- 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

« previous php.notes (#73037) next »