rogervila / array-diff-multidimensional Goto Github PK
View Code? Open in Web Editor NEWRecursively compare the difference between two multidimensional arrays in PHP
Home Page: https://rogervila.es
Recursively compare the difference between two multidimensional arrays in PHP
Home Page: https://rogervila.es
It would be interesting to have an option to get an arrays of keys only, maybe like: ['a', 'c.f']
.
Here are some tests
Numbers
$a = [1];
$b = [PHP_FLOAT_EPSILON + 1];
$r = ArrayDiffMultidimensional::compare($a, $b);
// expected: [1], actual: []
var_dump($r);
Arrays
$a = [[]];
$b = [1];
$r = ArrayDiffMultidimensional::compare($a, $b);
// expected: [[]], actual: []
var_dump($r);
References
$a = [1, 2, &$a];
$b = [1, 2, &$b];
$r = ArrayDiffMultidimensional::compare($a, $b);
// expected: [], actual: infinite recursion
var_dump($r);
I have a relation attached to the models I am comparing. Now said relation is basically a relation that show's the competitors
attached to a race. In my case the competitors
length is always 2, there is always only 2 competitors per race.
old data:
$old = [
"id" => 17
"description" => "Test"
"date" => "2021-08-22 10:51:00"
"competitors" => [
0 => [
"id" => 9
"name" => "John Doe"
"country_code" => "CA"
]
1 => [
"id" => 63
"name" => "Bob Rob"
"country_code" => "CA"
]
]
]
new data:
$new = [
"id" => 17
"description" => "Test"
"date" => "2021-08-22 10:51:00"
"competitors" => [
0 => [
"id" => 9
"name" => "John Doe"
"country_code" => "CA"
]
1 => [ ######################### <- difference
"id" => 101
"name" => "Tom Link"
"country_code" => "US"
]
]
]
naturally from this comparison I get only the modified data.
1 => [ "id" => 101 "name" => "Tom Link" "country_code" => "US" ]
However, in my case I absolutely need to get both of the values from the competitors
array even if only one of them has been modified. What would be the most efficient way of going about this?
Thank you.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.