Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Comments

Arrays::updateDiff()#246

Open
milo wants to merge 2 commits intonette:master from
milo:pull-array-diff
Open

Arrays::updateDiff() #246
milo wants to merge 2 commits intonette:master from
milo:pull-array-diff

Conversation

@milo
Copy link
Member

@milo milo commented Jan 7, 2021
edited
Loading

  • new feature
  • BC break? no
  • doc PR: will

Proposed Arrays::updateDiff() compares two associative arrays and returns such items from later one, which does not exist or differs from first one. By other words - which items have to be updated in first array, to be the same as second array.

As far as I know, there is no PHP function for that (playground). For examle:

$from = ['a' => null];
$to = ['a' => false];
# I didn't find a PHP function which returns
$diff = ['a' => false];

There are posible things to debate:

  • function name
  • arguments order
  • recursive version
  • objects comparing
  • 3rd argument callable $comparator = null

Copy link
Contributor

So it's like array_diff_assoc but with strict comparision?

Copy link
Member Author

milo commented Jan 8, 2021

Yes. Behaviour probably same as:

return array_udiff_assoc($to, $from, function ($a, $b) {
	return $a === $b ? 0 : ($a > $b ? 1 : -1); # spaceship cannot be used because null <=> false === 0
});

I write probably, because I'm not sure why yes/no comparator can return -1/0/1 and how result depends on it.
And the foreach loop is ~3 times faster.

@dg dg force-pushed the master branch 4 times, most recently from 740520b to 2bc2f58 Compare January 11, 2021 03:06
@dg dg force-pushed the master branch 11 times, most recently from eb3a987 to adead06 Compare March 4, 2021 20:13
@dg dg force-pushed the master branch 3 times, most recently from c5fe864 to f06376c Compare April 22, 2021 16:23
@dg dg force-pushed the master branch 2 times, most recently from 1d3a574 to f857e45 Compare August 16, 2021 21:07
@dg dg force-pushed the master branch 2 times, most recently from 2aa5187 to 9f1c637 Compare August 24, 2021 11:32
@dg dg force-pushed the master branch 2 times, most recently from e673736 to 299a857 Compare January 9, 2026 09:58
@dg dg force-pushed the master branch 13 times, most recently from 167d27a to 2ddfcc6 Compare February 10, 2026 05:52
@dg dg force-pushed the master branch 14 times, most recently from 7c0abb7 to bb3ea63 Compare February 13, 2026 03:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /