Skip to content

WIP all_empty and any_empty #14334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from

Conversation

elminson
Copy link

My proposal involves the introduction of two new methods, any_empty and all_empty, for working with arrays. These methods are designed to provide boolean outputs indicating whether any of the elements in an array are empty, or if all elements are empty, respectively. I believe these methods will be valuable additions to PHP’s array manipulation functionalities.

Below is a brief overview of the proposed methods:

any_empty(array $array): bool - This method will return true if any element in the provided array is empty, and false otherwise.
all_empty(array $array): bool - This method will return true if all elements in the provided array are empty, and false otherwise.
These methods aim to simplify common array checks and improve code readability and efficiency.

@NattyNarwhal
Copy link
Member

You should probably go through an RFC for new user-visible features. The RFC process will help you refine the scope and implementation.

@elminson
Copy link
Author

You should probably go through an RFC for new user-visible features. The RFC process will help you refine the scope and implementation.

@NattyNarwhal I will do it! thank you!

@TimWolla
Copy link
Member

In fact the implementation of this PR appears to match the PR #14108 (without giving credit), which is the PR for this RFC that is currently in voting: https://wiki.php.net/rfc/array_find

Personally I do not find it useful to have extra functions specifically for working with empty(). The semantics of empty() are terrible and it can easily be replicated in userland with

array_all($array, fn ($v) => empty($v));

@elminson
Copy link
Author

elminson commented May 27, 2024

My original branch was created on Feb 5 but never got the change to finish i, closing this PR

@elminson elminson closed this May 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants