php / php/doc-en

array_filter Flag will ignored when callable is null

Open
#2,285 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Category: Arrays Extension: standard
Dominant language
XML
Stars
596
Forks
890
Avg merge
1d 15h
Merged PRs (30d)
55

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the array_filter manual page linked in the report and compare its description of a null callback with the supplied ARRAY_FILTER_USE_BOTH and ARRAY_FILTER_USE_KEY examples. Done means the documentation clearly states the flag behavior and the expected handling of empty keys and values.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
documentation
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.