Skip to content

array_filter Flag will ignored when callable is null #2285

Open
@tinostief

Description

@tinostief

From manual page: https://php.net/function.array-filter


If the callback parameter is set to null, the flag is ignored. I expect array_filter to use an empty check for the mode used on key, or value, or both. But the flag is ignored and each time only the value is checked for empty.

Example:

array_filter([''=>'2',0=>'3',0,5=>3,null,'',[]], null, ARRAY_FILTER_USE_BOTH); does not filter the elements where key or value are empty. Only the elements where value is empty are filtered.

I expected all elements where key or value are empty to be filtered.

and

array_filter([''=>'2',0=>'3',0,5=>3,null,'',[]], null, ARRAY_FILTER_USE_KEY); does not filter the elements where key is empty. Only the elements where value is empty are filtered.

I had expected that all elements whose keys are empty would be filtered.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions