note 85584 added to function.array-walk

From: Date: Sun, 07 Sep 2008 03:10:30 +0000
Subject: note 85584 added to function.array-walk
Groups: php.notes 
Request: Send a blank email to php-notes+get-144208@lists.php.net to get a copy of this message
On array_walk and create_function used within a class scope - Anonymous functions are out of scope. So, if you want to access $this within the anonymous function, you'd have to pass it through the third parameter... <?php // example copies all values into $this where key is the same as property name array_walk($array, create_function('$v,$k,&$that', 'if (property_exists($that,$k)) {$that->$k = $v;}'), $this); // or, switch it around and array_walk the object array_walk($this, create_function('&$v,$k,$array','if (array_key_exists($k,$array)) {$v = $array[$k];}'), $array); ?> ---- Server IP: 208.69.120.35 Probable Submitter: 24.107.184.98 ---- Manual Page -- http://www.php.net/manual/en/function.array-walk.php Edit -- https://master.php.net/note/edit/85584 Del: integrated -- https://master.php.net/note/delete/85584/integrated Del: useless -- https://master.php.net/note/delete/85584/useless Del: bad code -- https://master.php.net/note/delete/85584/bad+code Del: spam -- https://master.php.net/note/delete/85584/spam Del: non-english -- https://master.php.net/note/delete/85584/non-english Del: in docs -- https://master.php.net/note/delete/85584/in+docs Del: other reasons-- https://master.php.net/note/delete/85584 Reject -- https://master.php.net/note/reject/85584 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#144208) next »