0

Hey guys I messed up my Lambda somehow and it seems like my anonymous function isn't getting the variables from above,

Some of the vars going in are

print_r($cacheTypes); 
print_r($servers); 

Array
(
    [concreter] => on
    [config] => on
)
Array
(
    [0] => dev-www.domain.com
)

the function is

$urls = array_walk($servers, 
    create_function('&$n', 
        '$n = "http://{$server}/".($vcpParam 
            ? "flush-file-cache" 
            : "flushFileCache.php"
        )."?tags=".implode("-", array_keys($cacheTypes));'
    )
);

errors are

Warning: array_keys() expects parameter 1 to be array, null given
Warning: implode() [<a href='function.implode'>function.implode</a>]: Invalid arguments passed

Help greatly appreciated. I'm positive it is not recognizing the variables I'm inputing, but I'm not sure why

2
  • What PHP version are you running? Commented Oct 16, 2012 at 17:17
  • I'm not terribly familiar with lambda functions, but in a regular PHP function you would need to declare the variables as globals in the function: global $cacheTypes; Commented Oct 16, 2012 at 17:19

1 Answer 1

6

You can use

$urls = array_map(function ($var) use($cacheTypes, $vcpParam) {
    return "http://{$var}/" . ($vcpParam ? "flush-file-cache" : "flushFileCache.php") . "?tags=" . implode("-", array_keys($cacheTypes));
}, $servers);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.