Skip to content

Conversation

@alipowerful7
Copy link
Contributor

This PR adds a new Arr::diff() method — a simple, expressive wrapper around PHP’s array_diff().

Comment on lines +1237 to +1247
/**
* Get the values in the first array that are not present in the other given arrays.
*
* @param array $array
* @param array ...$arrays
* @return array
*/
public static function diff(array $array, array ...$arrays)
{
return array_diff($array, ...$arrays);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it make sense to include all the array diffing methods into this one to make it easier for developers?

Honestly, I don't have a good idea myself as this would potentially require combining the variadic argument with an optional flag (ARRAY_DIFF_KEY¹/ARRAY_DIFF_VALUE or ArrKeyValue::Key/ArrKeyValue::Value or the like and callable), that would preferably come after all the arrays as it is optional but this is not allowed in PHP, but maybe someone has a clever idea here 🤔

¹ like ARRAY_FILTER_USE_KEY and ARRAY_FILTER_USE_VALUE

Copy link
Contributor Author

@alipowerful7 alipowerful7 Oct 26, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incidentally, I thought about this too, but I came to the conclusion that it would be better to add only the methods that the programmer really needs to Arr.
That's why I only added array_diff

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why would this be the only one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants