Skip to content

Conversation

rogervila
Copy link
Owner

Adds a global array_diff_multidimensional() helper function.

$new = [
	'a' => 'b',
	'c' => [
		'd' => 'e',
		'f' => 'Hello',
	],
];

$old = [
	'a' => 'b',
	'c' => [
		'd' => 'e',
		'f' => 'Goodbye',
	],
];

$result = array_diff_multidimensional($new, $old);

var_dump($result);

// [
// 	'c' => [
// 		'f' => 'Hello'
//  	],
// ]

@rogervila rogervila self-assigned this Jul 23, 2021
Co-authored-by: William Desportes <[email protected]>
@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@sonarqubecloud
Copy link

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@rogervila rogervila marked this pull request as ready for review October 28, 2021 08:07
@rogervila rogervila merged commit d5afb18 into master Oct 28, 2021
@rogervila rogervila deleted the helper-function branch October 28, 2021 08:07
@shadowhand
Copy link

It bothers me that this is defined as a global function instead of a function in the Rogervila namespace.

@rogervila
Copy link
Owner Author

Hi @shadowhand, this is an interesting point of view.

The idea is to have access to array_diff_multidimensional() the same way as PHP's native array_diff() function.

Since the original class is already namespaced, it can be used in case there is a conflict with the global helper.

Anyway, if you find a corner case related to the global helper function, do not hesitate to open an issue or even a PR.

Thank you very much for your feedback!

@shadowhand
Copy link

shadowhand commented Oct 29, 2021

@rogervila my reasoning is pretty simple: array_diff_multidimensional is not a native PHP function and so putting it in the global (root) namespace doesn't make sense to me.

I have no problem with having a helper function, but using a polyfill approach ( if (! function_exists(...)) ) basically proves my point, the global namespace shouldn't be polluted with arbitrary functions.

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