Re: [PHP-DEV] any solution about array_walk with pass-by-reference UseData?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Online document say's
Note: Please note that this function only checks one dimension of a
n-dimensional array. Of course you can check deeper dimensions by
using, for example, array_udiff_uassoc($array1[0], $array2[0],
"data_compare_func", "key_compare_func");.

It's not my needed

My need is
$disable_full=array("a","b","c");
$disable_start=array("_","HTTP");

$check_array=array(array("http"=>"a"),"a"=>"dabdd");


I want to unset all element's key full match in $disable_full and
start with string in $disable_start array;

2010/1/13 Joey Smith <joey@xxxxxxxxxxxxx>:
> This might be better served by taking it to php-general, because I don't
> think you need to pin your question so hard to the behaviour of
> array_walk(). Here's a quick example of (if I understood your question
> correctly) how you might solve it using array_udiff_uassoc and 5.3's new
> 'closure' syntax (not required for this, but I do so enjoy using them!)
>
> <?php
> $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'));
>
> function buildFilter($keys, $starts_with) {
>   return function ($a, $b) use ($keys, $starts_with) {
>      if (in_array($a, $keys)) return 0;
>      foreach($starts_with as $value) if (strpos($a, $value)===0) return 0;
>      return 1;
>   };
> }
>
> $foo = buildFilter($disable_full, $disable_start);
>
> var_dump(array_udiff_uassoc($check_array, $disable_full, $disable_start, function () { return 0; }, $foo));
>
>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux