Warning: array_filter() expects at Most 2 Parameters, 3 Given

Asked

Viewed 1,632 times

3

I have the following code that was taken from example #3 in the PHP documentation for the function array_filter():

$arr = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4);

var_dump(array_filter($arr, function($k) {
    return $k == 'b';
}, ARRAY_FILTER_USE_KEY));

Interestingly, when testing this code to answer in this question, I got the following error:

Warning:
array_filter() expects at Most 2 Parameters, 3 Given in /path/to/file.php on line X

See on the Ideone.

But in the documentation, the function is described as capable of accepting 3 parameters:

array array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )

The third parameter is exactly why you were using this function to solve the problem.

Question

What’s happening so I can’t make use of the three parameters?


Version of PHP: 5.3.22 | Host: Linux | Server API: CGI/Fastcgi

  • I have encountered this problem once before and I have not found a solution

  • 2

    Reading the documentation, it seems to be version problem. I added as an answer down there.

1 answer

2


Of documentation of function array_filter:

5.6.0 Added optional flag Parameter and constants ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_BOTH

Your PHP version does not support the third argument from flag.

  • 1

    Hmm... Okay, I just saw this note. Just from the version 5.6.0 is that we have the third parameter. Lack of attention on my part, had not read this block. Thank you.

  • hassle-free ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.