D
D
Dmitry Sonko2013-10-06 15:38:31
PHP
Dmitry Sonko, 2013-10-06 15:38:31

Computing the difference between two associative arrays

Not so long ago I ran into a problem, when collecting statistics from one of the services, an associative array of data comes in response. It is necessary to be able to store all this amount of data so that in the future it would be possible to restore the state at any point in time. Data comes every 5-10 seconds, storing the entire array in the database is not good, so I ran into a problem. It is necessary to find a solution with which you can get a diff between two arrays in the form of a third one, namely: which of the keys were removed, which keys had their value changed, which ones were added. Perhaps someone has come across something similar? I will be extremely grateful.

PS: I know about array_diff_*/array_udiff_* functions, but in any case, I have to use a complex of these functions. Suddenly there is a more beautiful and simple solution.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Cherepanov, 2013-10-07
@fear86

Yes, something is not completely clear, arrays, database, store completely but not completely =)
Array_ functions will work best, since they are native. If this is the base, then you can calculate the discrepancies using it. If these are incremental backups, then myqldump + gzip =)) Or, in general, full logging of requests, again with packing in gzip.
Need more information.
PS: It is also not clear how much data and what load. And why is it not good to store everything in the database.

M
Maxim Barulin, 2013-10-07
@Slavenin999

I don’t think that you can come up with something better than array_diff_assoc or array_diff_uassoc , when I solved a similar problem I used them, I didn’t find a better solution,
and if you need to store really large volumes, you can look towards NoSql, for example mongo

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question