Warning: array_filter () expects at most 2 parameters, 3 given

4

I have the following code that was taken from example # 3 in the PHP documentation for 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));

Curiously, when I tested 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

View on Ideone .

But in the documentation, the function is described as being able to accept 3 parameters:

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

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

Question

What is happening to not being able to use the three parameters?

PHP version: 5.3.22 | Host: Linux | Server API: CGI / FastCGI

    
asked by anonymous 14.11.2014 / 22:44

1 answer

3

From the documentation of the array_filter function:

  

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 of flag .

    
14.11.2014 / 23:02