NYCPHP Meetup

NYPHP.org

[nycphp-talk] How does one suggest improved variable scoping for PHP?

Dan Cech dcech at phpwerx.net
Wed Nov 16 11:20:24 EST 2011


On 11/16/2011 11:12 AM, Jim Williams wrote:
> 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:

Would this do the job?

function array_sanitize($array,$filterName)
{
   return array_diff($array,array_filter($array,$filterName));
}

Seems to work in my testing:

$a = array('a'=>6,'b'=>1,'c'=>4,'d'=>9);
$isOdd = create_function('$arg','return $arg % 2 == 1;');
print_r(array_sanitize($a, $isOdd));

Dan



More information about the talk mailing list