I just ran across a simple problem I couldn't solve, namely to create a function that does the opposite of array_filter, call it array_sanitize. The closest I could come doesn't work for anonymous functions:

<?php
  function array_sanitize($array, $filterName) {
    $negFilter = create_function('$arg', 'return !'.$filterName.'($arg);');
    return array_filter($array, $negFilter);
  }
  //Example:
  $a = array('a'=>6,'b'=>1,'c'=>4,'d'=>9);
  function isOdd($arg) { return $arg % 2 == 1; }
print_r (array_sanitize($a, 'isOdd')); // outputs 'Array ( [a] => 6 [c] => 4 )'
?>

If we had variables of intermediate scope, call them "regional" variables, we could do this:
/*
  function array_sanitize($array, $filter) {
    $negFilter = function($arg) {
      regional $filter;
      return !$filter($arg)
    };
  return array_filter($array, $negFilter)
  }
*/

So, my question is how and whether to advocate the need for variables of intermediate scope.
Specifically, is there a public forum for suggesting improvements to PHP?

Jim Williams
J. G. Williams Design

_______________________________________________
New York PHP Users Group Community Talk Mailing List
http://lists.nyphp.org/mailman/listinfo/talk

http://www.nyphp.org/Show-Participation

Reply via email to