any solution about array_walk with pass-by-reference UseData?

From: Date: Tue, 12 Jan 2010 19:45:03 +0000
Subject: any solution about array_walk with pass-by-reference UseData?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-46656@lists.php.net to get a copy of this message
In Online Document say's:
Users may not change the array itself from the callback function. e.g.
Add/delete elements, unset elements, etc. If the array that
array_walk() is applied to is changed, the behavior of this function
is undefined, and unpredictable.

So I'm use Use Optional param( [, mixed $userdata ])

here is my code
========================================================
$return=array();
$disable_full=array('a','b','c');
$disable_start=array('_','!','HTTP'/*,'ddd','ddd','ddd','ddd','ddd'*/);
$check_array=array("a"=>1,"_POST"=>'c',"HTTP"=>"f","ddd"=>array('fefe'));
array_walk($check_array,'walk_fun_with_foreach',&$return);

print_r($return);

function walk_fun_with_foreach(&$source,$key,$return){
       global $disable_full,$disable_start;
       //var_dump($key);
       if(is_array($source)){
               array_walk($source,'walk_fun_with_foreach',&$return);
       }else{

               if(in_array(strval($key),$disable_full)){
                       //exit;
                       return;
               }else{
                       foreach($disable_start as $key1 => $value){
                               if(strpos($key,$value)===0){
                                       //echo $key;
                                       return;
                               }
                       }
               }
               //echo $key;
               $return[$key]=$source;
       }
}
==========================================================
it's print :
Array ( [0] => fefe )

but in version php5.2.x and higher version,display Warning message:
Warning: Call-time pass-by-reference has been deprecated in

If I'm change
array_walk($check_array,'walk_fun_with_foreach',&$return);
to
array_walk($check_array,'walk_fun_with_foreach',$return);

and
declare function like
function walk_fun_with_foreach(&$source,$key,&$return)
no Warning Display
But result is not my needed.
Anyone has solution about is?I'm don't like use foreach for
instead,beacuse of some preformance reason.


Thread (3 messages)

« previous php.internals (#46656) next »